How do I create an associative array with the following string?size:3|order_by:date|order:ASC|post_type:post
to
Array
(
"size" => 3,
"order_by" => "date",
"order" => "ASC",
"post_type" => "post"
)
Like this
$str = 'size:3|order_by:date|order:ASC|post_type:post';
$arr = explode('|', $str);
foreach ( $arr as $a){
$t = explode(':', $a);
$new[$t[0]] = $t[1];
}
print_r($new);
RESULT
Array
(
[size] => 3
[order_by] => date
[order] => ASC
[post_type] => post
)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments