ok Posted November 22, 2008 Share Posted November 22, 2008 Hi I have these very simple codes below, $name = 'robert anderson'; $array_name=[$name][] = banana; I tried this but it's wrong. Can anyone show me the right way. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/133761-array-question-is-this-keyname-insertion-correct/ Share on other sites More sharing options...
JasonLewis Posted November 22, 2008 Share Posted November 22, 2008 What exactly are you trying to achieve? $name = "Robert Anderson"; $array_name[$name] = "Banana"; echo $array_name['Robert Anderson']; //will output 'Banana' Please elaborate a little bit more. Link to comment https://forums.phpfreaks.com/topic/133761-array-question-is-this-keyname-insertion-correct/#findComment-696084 Share on other sites More sharing options...
ok Posted November 22, 2008 Author Share Posted November 22, 2008 thanks for your help ProjectFear but ok since you ask the complete logic, then here it is. Ok actually the $name does not contain one value only. The $name is also an array $name[0] = 'robert'; $name[1] = 'john'; $name[2] = 'james'; etc... What i wanted to do is i want to use $name to accept more than one value. Since because $name has more than one user name in it. example If $name[0] which is equal to 'robert' as key name it will accept assigned value in the 2nd index. that is why i needed 2 dimentional array. therefore, $name['robert'][] = 'george'; $name['robert'][] = 'linda; $name['robert'][] = 'emlie'; $name['robert'][] = 'glenda'; etc... but because $name array has more than one name needed to be assign values does i need to do this this way. $array_name=[$name][] = banana; then i can increment like this below, $array_name=[$name++][] = banana; to fill all the names with names. because each name in the $name has more than one sub names. Instead of using the individual name as a key name inside the bracket. But my original codes result into as an error message. Can someone guide me please. Thank you. Link to comment https://forums.phpfreaks.com/topic/133761-array-question-is-this-keyname-insertion-correct/#findComment-696091 Share on other sites More sharing options...
JasonLewis Posted November 22, 2008 Share Posted November 22, 2008 Okay, that still didn't make any sense to me. Link to comment https://forums.phpfreaks.com/topic/133761-array-question-is-this-keyname-insertion-correct/#findComment-696093 Share on other sites More sharing options...
ok Posted November 22, 2008 Author Share Posted November 22, 2008 can someone please help me? Link to comment https://forums.phpfreaks.com/topic/133761-array-question-is-this-keyname-insertion-correct/#findComment-696095 Share on other sites More sharing options...
redarrow Posted November 22, 2008 Share Posted November 22, 2008 you can only create single array or multidesimoll arrays that it......... <?php //single array... //array $john['first'] holds first name $john['first']="first name"; //single array. //array secound holds secound name $john['secound']="secound name"; //multidisimoll array.. //array john['first']['secound'] holds both the // arrays first name and secound name. $john['first']['secound']; /* Array ( [first] => first name [secound] => secound name ) */ //Print the array out result above.... //becouse the varable $john holds the arrays pring_r //prints them all out for you.. print_r($john); //echo array values out singley echo "<br><br> ".$john['first']." <br> ".$john['secound']." <br><br>"; //Show the array as echoed to browser. $res=implode('<br>',$john); echo "<br><br>$res<br><br>"; ?> Link to comment https://forums.phpfreaks.com/topic/133761-array-question-is-this-keyname-insertion-correct/#findComment-696103 Share on other sites More sharing options...
redarrow Posted November 22, 2008 Share Posted November 22, 2008 There nothink else we can add to the array to get, more info out off it...... $john['a']['b']['c'] <<< not allowed offset <?php //This array only has john in it only, nothink else //becouse it been set to john, $john['a']['b']="john"; echo $john['a']['b']; ?> Link to comment https://forums.phpfreaks.com/topic/133761-array-question-is-this-keyname-insertion-correct/#findComment-696107 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.