Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are parameters in array functions are in different order than in string functions? [closed]

Tags:

php

I was always wondering why in PHP array function we have $needle before the $haystack and vice versa in string functions. E.g.:

mixed array_search ( mixed $needle , array $haystack [, bool $strict = false ] )
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )

string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] )
int strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )

Is it another PHP sadness or there is some sort of logical explanation for this? The thing is I often can't remember which one is in what order - maybe that logic beyond this will help.

like image 733
povilasp Avatar asked Dec 23 '12 10:12

povilasp


People also ask

Which of the following function returns an array of all parameters provided to function?

func_get_args( ) returns an array of all parameters provided to the function, func_num_args( ) returns the number of parameters provided to the function, and func_get_arg( ) returns a specific argument from the parameters.

What does args mean in Javascript?

args is a rest parameter. It always has to be the last entry in the parameter list and it will be assigned an array that contains all arguments that haven't been assigned to previous parameters. It's basically the replacement for the arguments object. Instead of writing function max() { var values = Array. prototype.

Which keyword is used to access the array of arguments of a function?

You can access specific arguments by calling their index. var add = function (num1, num2) { // returns the value of `num1` console. log(arguments[0]); // returns the value of `num2` console.

How can you get the type of arguments passed to a function?

Passing Arguments There are two ways to pass arguments to a function: by reference or by value. Modifying an argument that's passed by reference is reflected globally, but modifying an argument that's passed by value is reflected only inside the function.


1 Answers

It is a php sadness that was introduced in the early versions of the language and never corrected to avoid such a BC breack. It is the first reason people invoke when they criticise php

like image 171
artragis Avatar answered Nov 14 '22 22:11

artragis