Hey. How to change the behavior of the standard PHP method for working with arrays and objects, how to add a new standard method? Something like this in js

Array.prototype.indexOf = function (vItem) { for (var i=0; i < this.length; i++) { if (vItem == this[i]) { return i; } } return -1; } var aColors = new Array("red", "green", "yellow"); alert(aColors.indexOf("green")); 

    1 answer 1

    Specifically for this option there is a standard function array_search() .

    And, in general, nothing prevents to create a function of the type:

     function func_name(&$array, $value){ foreach($array as $key=>$val) if($val==$value) return $key; return false; }