Jump to content

array question, is this keyname insertion correct?


ok

Recommended Posts

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
Share on other sites

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
Share on other sites

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.