mardi 26 mars 2019

How to remove an array from a Multidimensional array by key if condition is met Php

I have a array structured like so

array:2 [▼
  "id_1553623907416" => array:2 [▼
    "id_title" => "About"
    "id_content" => """
      <!DOCTYPE html>
      <html>
      <head>
      </head>
      <body>
      <p>Helllo world</p>
      </body>
      </html>
      """
  ]
  "id_1553623916174" => array:2 [▼
    "id_title" => "Education"
    "id_content" => """
      <!DOCTYPE html>
      <html>
      <head>
      </head>
      <body>
      <p>hello data</p>
      </body>
      </html>
      """
  ]
]

i need to be able to remove the array named id_1553623907416 if it contains the value About in the sub-array key id_title. The ids are dynamic so this has to be dynamically.

 @foreach ($output as $item)    
   @if($item["id_title"] == "About")
      //remove array 
   @else
     //do something else 
   @endif
@endforeach

Aucun commentaire:

Enregistrer un commentaire