I have a function (for ease, I'll just use count()) that I want to apply to maybe 4-5 different variables. Right now, I am doing this:
$a = count($a);
$b = count($b);
$c = count($c);
$d = count($d);
Is there a better way? I know arrays can use the array_map function, but I want the values to remain as separate values, instead of value...
I need to create an array of arrays.
I have been using array_map(null,$a,$b,$c) to do this and it works fine, however, it doesn't work if one of the mapped arrays doesn't exist.
To get around this problem I have used:
$myArray= array();
if (isset($a)) {
array_push($myArray,$a);
}
if (isset($b)) {
array_push($myArray,$b);
}
if (isset(...
Is it possible to use array_map() to test values of an array? I want to make sure that all elements of an array are numeric.
I've tried both
$arrays = array(
array(0,1,2,3 )
, array ( 0,1, "a", 5 )
);
foreach ( $arrays as $arr ) {
if ( array_map("is_numeric", $arr) === FALSE ) {
echo "FALSE\n...
hey all, i use array_map from time to time to write recursive methods. for example
function stripSlashesRecursive( $value ){
$value = is_array($value) ?
array_map( 'stripSlashesRecursive', $value) :
stripslashes( $value );
return $value;
}
Question:
say i wanna put this function in a static class, how would i use...
I'm trying to use empty() in array mapping in php. I'm getting errors that it's not a valid callback.
$ cat test.php
<?
$arrays = array(
'arrEmpty' => array(
'','',''
),
);
foreach ( $arrays as $key => $array ) {
echo $key . "\n";
echo array_reduce( $array, "empty" );
var_dump( array_map("empty...