Hello there,

I am trying to add more than 2 foreach statements. Please help me.

My statement -

foreach (array_combine($image, $name) as $pic => $title) {
}

It cant be like -

foreach (array_combine($image, $page, $name) as $pic => $id => $title) {
}

Hi,

the foreach construct only accept these syntaxes:

foreach (array_expression as $value)

And:

foreach (array_expression as $key => $value)

it seems you're trying to extract two keys, it won't work. The array_combine() function does accepts only two arguments, you're submitting three arguments (arrays) so it will fail.

If these are multidimensional arrays the you could use array_merge() and write:

$data = array_merge($image, $page, $name);
foreach($data as $key => $value) {

But consider the following statements from the documentation:

If you want to append array elements from the second array to the first array while not overwriting the elements from the first array and not re-indexing, use the + array union operator

And:

The keys from the first array will be preserved. If an array key exists in both arrays, then the element from the first array will be used and the matching key's element from the second array will be ignored.

Documentation:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.