All viewers I need help regarding PHP explode() function.
$line = 'dd=541;nn=874;cc=21;mm=95;tt=41';
$lineexp = explode(';', $line);
print_r($lineexp);
This will produce the following output:
[
0 => 'dd=541',
1 => 'nn=874',
2 => 'cc=21',
3 => 'mm=95',
4 => 'tt=41'
]
How can I get just the value of the array as array instead?
Desired output:
[
0 => 541,
1 => 874,
2 => 21,
3 => 95,
4 => 41
]
foreachloop… You could use explode again on the results, with "=" as parameter. Or you could use regex to clean each result. Or you could take a substr() of each result, as the "xx=" variables seem to be always the same lenght…$result = array_map(function($item) { return filter_var($item, FILTER_SANITIZE_NUMBER_INT); }, $data);.