Checking if the array contains same type variables like all numeric in php

Checking if the array contains same type variables like all numeric in php

I was in need of checking if the given array is all numeric or not. A colleague suggested with snippet the use of array_reduce – here the implementation

$numbers = array(1,22, 7, 34, 20);
$all_numbers = array_reduce($numbers, function($val1, $val2){
   return $val1 && is_numeric($val2);
}, TRUE);

Should do the trick.
zaTisIT!!

See how you would solve these known algorithm problems

Check if two strings are anagrams or not

find longest word in the sentence

Find the first occurence of number in the sorted array

Java solution for checking anagram strings – tell if phrases are anagrams

Find K Complementary numbers from array Java implementation

Implementing tokenizer and adding tokens to the linked list

Find the pairs that makes K Complementary in the given array java solution

Flatten nested javascript array

String Ordered Permutation Algorithm Problem

binary tree problems with solution

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*