Turn arrays into one foreach loop?

I have limited PHP knowledge, and I currently have this:

$Name= simple_fields_values('Name');
$Description= simple_fields_values('Description');
$Price= simple_fields_values('Price'); 

foreach ($Name as $key_name => $key_value) {
print  $key_value ;
}
foreach ($Description as $key_name => $key_value) {
print $key_value ;
}
foreach ($Price as $key_name => $key_value) {
print $key_value;
}

And i Just wanted to know if i can combine this into 1 foreach loop…im sure there is a way, i just dont have the knowledge!

Read More

Thanks!

Related posts

Leave a Reply

1 comment

  1. You can merge all these three arrays using array_merge and then you can use the merged array in a single foreach loop.

    For eg.,

    $Name= simple_fields_values('Name');
    $Description= simple_fields_values('Description');
    $Price= simple_fields_values('Price');
    
    $merge = array_merge($Name,$Description,$Price);
    
    foreach ($merge as $key_name => $key_value) {
    print $key_value ;
    }