PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
swetha
Forum Commoner
Posts: 88 Joined: Wed Sep 10, 2008 11:00 pm
Post
by swetha » Tue Nov 11, 2008 3:37 am
Code: Select all
$gdesc[$i] = explode("--",$all[$i]);
$sdesc[$i] = explode("-",$gdesc[$i][0]);
Consider this line $gdesc[$i] = explode("--",$all[$i]).In the second line,is it correct to give
gdesc[$i][0],since gdesc[$i] is one dimensional array and gdesc[$i][0] is 2 dimensional array.
novice4eva
Forum Contributor
Posts: 327 Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal
Post
by novice4eva » Tue Nov 11, 2008 3:49 am
it is perfectly CORRECT
swetha
Forum Commoner
Posts: 88 Joined: Wed Sep 10, 2008 11:00 pm
Post
by swetha » Tue Nov 11, 2008 4:47 am
how is that?
$gdesc[$i] = explode("--",$all[$i]);
$sdesc[$i] = explode("-",$gdesc[$i][0]);
$gdesc[$i] is one dimensional array but
$gdesc[$i][0] is 2 dimensional array.Then how come this works?thanks for help
Ziq
Forum Contributor
Posts: 194 Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh
Post
by Ziq » Tue Nov 11, 2008 5:03 am
After this line execute
Code: Select all
$gdesc[$i] = explode("--",$all[$i]);
$gdesc[$i] is 2 dimensional array. Because explode() function return array value and this one assign to 1 dimensional array $gdesc[$i].
Same happens if you try this
Code: Select all
// 1 dimensional array
$array[0] = 1;
$array[0] = array('2 dimensional');
// Now in $array is 2 dimensional array
echo $array[0][0]; // print: 2 dimensional
Read about explode() and Arrays.
novice4eva
Forum Contributor
Posts: 327 Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal
Post
by novice4eva » Tue Nov 11, 2008 5:11 am
if you do
Code: Select all
echo '<pre>';
print_r($gdesc);
echo '</pre>';
it will give you the hierarchical order, it always helps before drowning when things go really deeper in array