PHP - Pull ids from a string and convert to array -
i'm working on linking system , ui post hidden string below
"artwork:56,artwork:34,music:123"
this represent linking following media:
- artwork id:56
- artwork id: 34
- music id:123
what i'm trying figure out how feed in string above , spit out id's need.
function getartworkids($string){ //code needed }
results [56,34]
any awesome, thank you
$string = "artwork:56,artwork:34,music:123"; $a = explode(',',$string); $ids = array(); foreach($a $i){ if(strpos($i,"art") !== false){ $ids[] = explode(':',$i)[1]; } } var_dump($ids);
output: 56,34
the !== false
important, strpos
return 0
since string starts art
. without !== false
check you'd no results because if
treat 0
boolean false
Comments
Post a Comment