PHP Filter Multidimensional Array

PHP Filter Multidimensional Array Examples

Today, We want to share with you PHP Filter Multidimensional Array.In this post we will show you Filter Associative Multidimensional Array, hear for php remove empty array from multidimensional array we will give you demo and example for implement.In this post, we will learn about How to Filter Multidimensional Array by Key Value in PHP with an example.

PHP Filter Multidimensional Array

There are the Following The simple About PHP Filter Multidimensional Array Full Information With Example and source code.

  How to Open URL in New Tab using Vue JS

As I will cover this Post with live Working example to develop php get array key by value multidimensional, so the php remove empty array elements for this example is following below.

PHP Filter Array

Filtering Multi-Dimensional Arrays in PHP()

$myArr = array(
    array('name' => 'Jobar shah', 'email' => '[email protected]'),
    array('name' => 'Mayur Lies', 'email' => '[email protected]'),
    array('name' => 'Hiteshy Dhameliya', 'email' => '[email protected]'),
);

$strlike = 'jo';

$result = array_filter($myArr, function ($item) use ($strlike) {
    if (stripos($item['name'], $strlike) !== false) {
        return true;
    }
    return false;
});

OutPut:

Array
(
    [0] => Array
        (
            [name] => Jobar shah
            [email] => [email protected]
        )

    [2] => Array
        (
            [name] => Hiteshy Dhameliya
            [email] => [email protected]
        )

)

Example 2: Filter Multidimensional Array

Filtering Array by Mutiple Key Values:

<?php
$myarray = array(
    array("name"=>"John", "email"=>"[email protected]", "dept"=>"rohitsharma"),
    array("name"=>"aitsjd", "email"=>"[email protected]", "dept"=>"swami"),
    array("name"=>"Austin", "email"=>"[email protected]", "dept"=>"HR"),
    array("name"=>"patang", "email"=>"[email protected]", "dept"=>"rohitsharma"),
    array("name"=>"Milan", "email"=>"[email protected]", "dept"=>"swami")
);

$filter = array("aitsjd", "patang");

$new_array = array_filter($myarray, function($var) use ($filter){
    return in_array($var['name'], $filter);
});
echo "<pre>";
print_r($new_array);
?>

output:

Array
(
    [1] => Array
        (
            [name] => aitsjd
            [email] => [email protected]
            [dept] => swami
        )

    [3] => Array
        (
            [name] => patang
            [email] => [email protected]
            [dept] => rohitsharma
        )

)

Angular 6 CRUD Operations Application Tutorials

Read :

  Top 10 Advanced MySQL Interview Questions Answers

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Filter Multidimensional Array.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Reply

avatar
  Subscribe  
Notify of