我得到了一個字符串,我想爆炸成一個數組,但
問題是,我需要每一個項目的組合。使用foreach創建數組,同時將每個2項分組到鑰匙
例字符串:
http://www.example.com, example, http://www.example2.com, example2, http://www.example3.com, example3, http://www.example.com4, example4, http://www.example5.com, example5, http://www.example6.com, example6,
什麼,我想實現的是:
array(
[1]=>array(
[url] => 'http://www.example.com',
[name] => 'example',
),
[2]=>array(
[url] => 'http://www.example2.com',
[name] => 'example2',
),
[3]=>array(
[url] => 'http://www.example3.com',
[name] => 'example3',
),
[4]=>array(
[url] => 'http://www.example4.com',
[name] => 'example4',
),
[5]=>array(
[url] => 'http://www.example5.com',
[name] => 'example5',
),
[6]=>array(
[url] => 'http://www.example5.com',
[name] => 'example6',
),
);
等等...
我試圖創建在許多這樣的一個數組方式,但我想我缺乏
知道如何,並會真正apreaciate你的幫助。 ;)
EDIT 1(到目前爲止已經試過):
$csv_arr = array();
$keycounter = 1;
$counter = 1;
foreach($csv_data as $dataitem) {
if($counter % 2 == 0) {
$csv_arr[$keycounter]['keyword'] = $dataitem;
$keycounter++;
}
else {
$csv_arr[$keycounter]['url'] = $dataitem;
}
$counter++;
}
所以你到目前爲止嘗試什麼?顯示代碼! – djot
我的代碼doesent工作 - 我不需要一點點修復,我需要一個想法,一個指導方針... nevetheless - 我添加了我的非工作代碼(什麼爲!?!),而我嘗試@kingkero代碼。 –