Reputation: 907
php:
$getallvalues
Gives me the array from session:
array:7 [▼
"_token" => "ZCP63uasUQHl948oVVDG7ZO4x33"
"_previous" => array:1 [▶]
"flash" => array:2 [▶]
"key1" => "1"
"key2" => "2"
"id-2" => "2"
"id-3" => "3"
]
How to retrieve a new one array with wildcard key "id-" to give me the result:
array:2 [▼
"id-2" => "2"
"id-3" => "3"
]
I tryed some php methods like: array_values, in_array etc but nothing works as I expected.
Upvotes: 1
Views: 935
Reputation: 907
I found a better solution without foreach code in 2 lines only!!
$resultsession = preg_grep('/^id-[\d]*/', array_keys($getallsession));
$result = array_flip($resultsession);
Upvotes: 1