- array_combine: documentation ( source)
- print_r: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$str = "php/127/typescript/12/jquery/120/angular/50";
preg_match_all("/([^\/]*?)\/(\d+)/", $str, $match);
/* result:
Array
(
[0] => Array
(
[0] => php/127
[1] => typescript/12
[2] => jquery/120
[3] => angular/50
)
[1] => Array
(
[0] => php
[1] => typescript
[2] => jquery
[3] => angular
)
[2] => Array
(
[0] => 127
[1] => 12
[2] => 120
[3] => 50
)
)
*/
#then combine match[1] and match[2]
$result = array_combine($match[1], $match[2]);
/* result
Array
(
[php] => 127
[typescript] => 12
[jquery] => 120
[angular] => 50
)
*/
print_r($result);