我有一个看起来像这样的数组,它由:
生成$file = fopen($savedSource,"r");
while(! feof($file)) {
$data = (fgetcsv($file));
}
Array
(
[0] => First Name
[1] => Last Name
[2] => Title
[3] => Company / Account
[4] => Email
[5] => Lead ID
[6] => Profile Image
Zelayas
[7] => Zelayas
[8] =>
[9] => Kramer
[10] => zel@somewhere.com
[11] => 123456
[12] => https://media.com/0f48c22.jpg
Kanngiesser
[13] => Kanngiesser
[14] =>
[15] => Johnson
[16] => kanngie@somewhere.com
[17] => 7891234
[18] => https://media.com/135f3b7.jpg
我希望能够将这些URL存储到一个简单的(无嵌套)数组中,以便结果变为:
Array
(
[0] => https://media.com/0f48c22.jpg
[1] => https://media.com/135f3b7.jpg
===编辑=== 从选定的答案中,我基本上能够实现我的目标。
$new_array = array();
foreach($data as $a){
if(substr( $a, 0, 4 ) === "http"){
array_push($new_array, $a);
}
}
结果,$ new_array正在给我
Array
(
[0] => https://media.com/0f48c22.jpg
Kanngiesser
[1] => https://media.com/135f3b7.jpg
Mostovoy
所以看起来脚本正在查看当前行的最后一个字段以及下一行AS ONE FIELD的第一个字段。
答案 0 :(得分:1)
您可以使用substr
检测字符串开头的http
。
$new_array = array();
foreach($old_array as $a){
if(substr( $a, 0, 4 ) === "http"){
array_push($new_array, $a);
}
}
答案 1 :(得分:0)
$new=array();
foreach ($array as $check){
if(substr($check,0,4)=='http')
$new[]=$check;
}