Jump to content

[SOLVED] help with arrays


anatak

Recommended Posts

Hello I am banging my head against some array stuff.

 

can someone explain how the syntax works to run through an array ?

 

I have an array $content and in that array is an index $cat_id

 

but I have no idea what the =>$category means

 

Can anyone explain or give me a link to a clear basic tutorial ?

I looked a the php page of array functions but I got lost there.

 

foreach ($content as $cat_id=>$category){

}

 

kind regards

anatak

Link to comment
https://forums.phpfreaks.com/topic/50133-solved-help-with-arrays/
Share on other sites

Hi!

I give you two examples:

You got an array like that:

<?php
$arr[0] = 'hello';
$arr[2] = 'foo';
$arr[1] = 'world';
$arr[3] = 'bar';

foreach ($arr as $index => $value) {
	echo "$index => $value<br>\n";
}
?>

You see... the result is the same as you'r definition:

0 => hello
2 => foo
1 => world
3 => bar

 

Now the second example:

<?php
$arr['hello'] = 'world';
$arr['foo'] = 'bar';

foreach ($arr as $index => $value) {
	echo "$index => $value<br>\n";
}
?>

You also get the index and the value:

hello => world
foo => bar

 

I think now you know what $index => $value means ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.