[wd_asp elements=’search’ ratio=’100%’ id=1]

Add only Numeric parts of array to a string

23rd January 2015

Php - Arrays

php codehaven

array (size=10)
‘animal’ => string ‘DOG’ (length=9)
‘age’ => string ’78’ (length=9)
‘name’ => string ‘fido’ (length=4)
‘toy’ => string ‘ball’ (length=22)
0 => string ‘leg’ (length=6) // I only want the numeric into a string
1 => string ‘arm’ (length=11)
2 => string ‘tail’ (length=4)
3 => string ‘eyes’ (length=3)
4 => string ‘ears’ (length=12)
5 => string ‘feet’ (length=3)

$metrics = '';
foreach ($mysession as $key => $value) {

if (is_numeric($key)) {
$metrics .= $value . ',';
}
}

Metrics would look like this “leg,arm,tail,eyes,ears,feet,”

Just take off the last character

$metrics = substr_replace($metrics ,"",-1);