PHP foreach loop show category name onces json multidimensional array


I have an multidimensional array in which there are three fields substitute name,substitute category and price. I have this is on foreach loop. I want to show category name once and under this substitute name.

     Array ( 
          [sub1] => 

     Array ( [substitute] => 2 
             [substitute_category] => 7 
             [substitute_price] => 123 ) 

         [sub2] => 

    Array ( 
           [substitute] => 3 
           [substitute_category] => 7 
           [substitute_price] => 139 
         [sub3] =>

 Array ( [substitute] => 4 
         [substitute_category] => 7 
         [substitute_price] => 150 ) 



It ain't that hard.

echo $category."<br />";
foreach ($array as $sub) {
    echo $sub['substitute_category']."<br />";

If you already had the foreach, what exactly is your problem?

People are also looking for solutions to the problem: php mysql not deleting from database


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.