Utility php function can be reused to save development time
Use composer
Checks if value exists in array
Example
$data = ['One', 'Two', 'Three'];
var_dump(\Asca\array_value_exist('One', $data)) // true
var_dump(\Asca\array_value_exist('Five', $data)) // false
Fast Array Unique
Example
$data = ['One', 'Two', 'Three', 'Three'];
var_dump(\Asca\fast_array_unique($data)); // [0 => 'One', 1 => 'Two', 3 => 'Three']
var_dump(\Asca\fast_array_unique($data, true)); // [0 => 'One', 1 => 'Two', 2 => 'Three']
Retrieve a value from multi-dimensional array by key path
Example
$data = [
'employees' => [
'junior' => [
'name' => 'John',
'years' => 1
],
'intermediate' => [
'name' => 'Sara',
'years' => 2,
],
'senior' => [
'name' => 'Ahmed',
'years' => 5
]
]
];
var_dump()\Asca\value_by_key_path($data, 'employees/junior/name'); // John
Get all elements from both arrays
Example
$array1 = ['One', 'Two', 'Three', 'Four', 'Five'];
$array2 = ['Two', 'Four', 'Six', 'Eight', 'Ten'];
\Asca\array_diff_both($array1, $array2); //['One', 'Three', 'Five', 'Six', 'Eight', 'Ten']
Converts array to xml
Example
$array = [
'persons' => [
'person1' => [
'name' => 'John Doe',
'job' => 'Web Developer',
'years' => 5
]
]
];
echo \Asca\array_to_xml($array);
output:
<root>
<persons>
<person1>
<name>John Doe</name>
<job>Web Developer</job>
<years>5</years>
</person1>
</persons>
</root>
This is json_encode($array);
function
This is yaml_emit($array);
function