-
Types of data to be stored in an array
Does array in php accepts different data? I mean data with different types? PHP is like C but in C, arrays only accept data with the same datatype because variables in C including arrays are declared with a specific type like int, float, etc. In PHP, variables are not declared to any datatypes, so I'm just wondering about Arrays in PHP.
-
-
Try it. I haven't ever had problems with this. Certainly you can have any type of data in an array. I'm not sure about the rules of mixing it. You might have some weird errors if you try to apply something across the entire array, such as array_map() that expects the parts to be strings and they are instead something else.
But for example, you can always have each part of the array be either a string or any array [recursively], so that level of mixing IS allowed. I don't see why other mixing wouldn't be.
I think this is completely valid:
array(FALSE,0,'',array());
But as I said, you'll of course run into problems with that if you try to automate parsing the data.
The only case where I can see completely varied data being relevant is returning an array from a function. Instead of a single true/false response you may want that and the result (let's say a number). So the function outputs:
array(FALSE,5)
I don't see why that wouldn't be valid and it might be useful.
In other words, I've never seen anything to lead me to believe that array parts are special-- they're just regular variables referred to as part of a group.
Someone else may know the technical details, though.
Daniel -
Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks