开发者

php string in to array (key and val must be same string)

开发者 https://www.devze.com 2022-12-25 21:47 出处:网络
Using explode i have converted the string into array, But the array look like Array ( [0] => root) But i want i make my array somthing like Array ( [root] => root)

Using explode i have converted the string into array ,

But the array look like Array ( [0] => root)

But i want i make my array somthing like Array ( [root] => root)

开发者_JAVA百科

How to make this manner..

Thanks


$array = explode($separator, $some_string);
$array = array_combine($array, $array);


You could make it an associative array like so:

$exploded = explode (.......);
$exploded_associative = array();

foreach ($exploded as $part) 
 if ($part) 
  $exploded_associative[$part] = $part;

print_r($exploded_associative); // Will output "root" => "root" ....

what exactly do you need this for?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号