php - Combine four foreach into one foreach? -
i trying add 4 foreach one. know how add 2 foreach 1 :
foreach (array_combine($images, $covers) $image => $cover) {
but want add more 2 foreach $titles $title
, $albums $album
. not sure want :
foreach (array_combine($images, $covers) $image => $cover) { foreach (array_combine($titles, $albums) $title => $album) { echo "$image-$cover-$title-$album"
it show me duplicate of every output.i mean output is
demo-demo1-demo2-demo3demo-demo1-demo2-demo3
need output
demo-demo1-demo2-demo3
put each statement in function. create loop calls it.
public function loopme($images, $covers) { foreach (array_combine($images, $covers) $image => $cover) { $this->loopme($image,$cover); } }
it looks second loop being called multiple times per item in first loop. want make sure calling second loop once per image cover. or set index cap on second loop. instance if tyring map first item in first loop first item in second loop should use index.
public function loopme($images) { ($i = 0; $i < count($images); $i++) { echo $images[$i] . '-'. $title[$i] . '-' . $cover[$i] . '-'. $album[$i]; } }
Comments
Post a Comment