Removing non-integer entries from array in php
Here we are going to discuss how to remove strings or non-integer values from an array in php.
For this we need to use one simple array function in php called array_filter() . it always filters an array using a callback function.
Syntax :
array_filter(array, callbackfunction, flag)
Parameters :
- array :- required, is the array to be filtered
- callbackfunction :- optional, the callback function
- flag :- optional, Specifies what arguments are sent to callback
Example
array([0] => 1,
[1] => 'one',
[2] => 2,
[3] => 'two',
[4] => 3);
Expected Result :
array([0] => 1,
[1] => 2,
[2] => 3);
Solution :
$result = array_filter($array, 'is_numeric');
Here you dont have to do any other steps as ‘is_numeric’ is a built in function, all you have to do is just call this line.
Click me for more intersting PHP Solutions.
Heya i’m for the first time here. I found this board and I find It
really useful & it helped me out much. I hope to give something
back and aid others like you aided me.
Thank you
Thanks for a marvelous posting! I quite enjoyed reading it, you happen to be a great author.
I will make sure to bookmark your blog and may come back at some point.
I want to encourage continue your great job, have a nice afternoon!
thank you so much
My brother recommendeԀ I might like this blog.
He was entirely right. This post actuallу madе my day.
You сann’t іmagine simplly how much timе I had spebt for this info!
Thanks!
Feel free to surf to my homepage – 야짤사이트
thank you