PHP code example of kimjangwook / array-util

1. Go to this page and download the library: Download kimjangwook/array-util library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kimjangwook / array-util example snippets


use KimJangwook\ArrayUtil\ArrayUtil;

// Test Varables
$testArr = [
    [ 'name' => 'a', 'age' => 30 ],
    [ 'name' => 'b', 'age' => 28 ],
    [ 'name' => 'c', 'age' => 30 ],
];
$trueCallback = function ($person) {
   return $person['age'] === 30;  
};
$falseCallback = function ($person) {
   return $person['age'] === 29;  
};

// find(): Shift value that result of the array_filter() function.
ArrayUtil::find($testArr, $trueCallback); // [ 'name' => 'a', 'age' => 30 ]
ArrayUtil::find($testArr, $falseCallback); // null

// exists(): Return true if item that is satisfied condition is exists
ArrayUtil::exists($testArr, $trueCallback); // true
ArrayUtil::exists($testArr, $falseCallback); // false