Tag: array

  • Remove the elements from array in php

    <?php $String_array=array(“a”,”b”,”c”,”d”); $string_search=”c”; echo “<pre>”; print_r($String_array); /* OUTPUT OF print_r($string_array); Array ( [0] => a [1] => b [2] => c [3] => d ) Now, We have to remove “c” value of element [2] from array */  unset($String_array[array_search($string_search, $String_array)]); /* * From Above code  : * first search the element from the array using…

  • Multi Dimensional array search in php

    <?php function md_search($arr, $searched) { if (empty($searched) || empty($arr)) { return false; } foreach ($arr as $key => $value) { $exists = true; foreach ($searched as $skey => $svalue) { $exists = ($exists && IsSet($arr[$key][$skey]) && $arr[$key][$skey] == $svalue); } if($exists){ return $key; } } return false; } $arr = array(); $arr[] = array(‘color’=>’red’, ‘qty’=>3);…