你会如何格式化这个数组?

时间:2017-06-22 15:26:21

标签: php

所以我有一个数组。它看起来像这样,是的,它是代理。

Array ( [0] => 
[29] => 1.164.146.151:80
[30] => 1.174.251.189:80
[31] => 1.175.136.1:3128
[32] => 1.175.142.176:3128
[33] => 1.179.176.37:8080
[34] => 1.179.183.109:8080
[35] => 1.179.183.89:8080
[36] => 1.179.185.249:8080
[37] => 1.179.189.217:8080
[38] => 1.179.198.17:8080
[39] => 1.194.129.104:808
[40] => 1.195.7.117:53281
[41] => 1.195.9.60:808
[42] => 1.197.200.131:808
[43] => 1.197.58.69:808
)

我如何制作它以便像这样格式化。我需要这个,因为curl只接受不同参数的代理和端口。我希望有人能为我回答这个问题。我试图也使用爆炸,它没有工作,因为它应该是一个字符串,而不是一个数组。

Array ( [0] =>
[29] => 1.164.146.151
[30] => 80
)

1 个答案:

答案 0 :(得分:1)

循环遍历数组并使用explode()

拆分字符串
$newArray = array();

foreach($array as $element)
{
    $newArray[] = explode(':', $element);
}

$array是您的原始数组,$newArray是准备好的数组

示例:https://eval.in/820983