By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,662 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

php arrays!

P: n/a
as we know if we dont ptovide the key in array by default it uses 0
and n + 1 for keys
example

$arr = array("raashid", "aslam", "bhatt");

it is same as
$arr = array (0 ="raashid", 1 =>............, 2 =>....);

and another example
$arr = array("raashid", 2 ="aslam", "bhatt");
0 2 3

the value raashid will automatically get value 0
while as aslam stays at 2 (note we can rearrange them using
array_vaules() function)

bhatt will automatically get 3 because as i stated early n + 1 for
keys

that was just an intro my main point is

$arr = array("raashid", "2" ="aslam", "bhatt");

here the key("2") is a string and it must not use n + 1

bhatt's key should be 1 as 0 + 1 = 1

now

var_dump($arr);
array(3) { [0]= string(7) "raashid" [2]= string(5) "aslam" [3]=>
string(5) "bhatt" }

see the key for raashid is converted into integer but it was not

and bhatt gets key 3 thst is previous + 1
Aug 14 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Aug 14, 8:52*am, raashid bhatt <raashid_...@yahoo.comwrote:
$arr = array("raashid", "2" ="aslam", "bhatt");

here the key("2") is a string and it must not use n + 1

bhatt's key should be 1 as 0 + 1 = 1
You are basically right, but the string "2" is converted to the
integer 2 already by array():

$arr = array("1" ="one");
var_dump($arr);

gives
[1] =string(3) "one"

instead of
["1"] =string(3) "one"
Aug 14 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.