php - Remove Json row that contains a specific value -


i've got json output 3 values.

{"contacts":[{"id":"1","name":"one"},{"id":"2","name":"two"},{"id":"3","name":"three"}]} 

and remove row id equal 2, , output this:

 {"contacts":[{"id":"1","name":"one"},{"id":"3","name":"three"}]} 

my code

$output = array(); while($row = mysqli_fetch_assoc($result))   {     $output[] = $row;   }        $json = json_encode(array(     "contacts" => $output ));      echo strip_tags($json); 

how can that? thanks

aside obvious:

while($row = mysqli_fetch_assoc($result)) {     if ($row['id'] != '2') { $output[] = $row; } } 

what doing returning array, filtered version of it. use array_filter:

$json = json_encode(array(             'contacts' => array_filter(function($row) {                  return $row['id'] != '2';              }, $output)          )); 

since getting results query, add where id != 2 query doesn't come begin with.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -