0
インデックス値を使用して文字列/配列を並べ替える方法を探しています。インデックス値から配列を並べ替える方法
例:文字列(1,2,3,4,5)(1,5,2,3,4)
$string = "1,a,v,v|2,b,v,v|3,c,v,v";
// Convert string to array first...
$sections = explode ('|', $string);
$current_index = "1";
$new_index = "2";
$arrReorder = array();
foreach($sections as $key => $val){
if ($key = $current_index) {
$arrReorder[$new_index] = $val;
}
else {
$arrReorder[$key] = $val;
}
}
$new_string = implode("|", $arrReorder);
echo $new_string;
$new_string
に変更してください出力「1、V、V | 3、C、V、V | 2、B、V、V」