array:32 [▼
"ID" => "7917"
"ProvinceCode" => "MB"
"Create" => "2016-05-18 18:16:26.790"
"DayOfTheWeek" => "4"
"Giai1" => "28192"
"Giai2" => "83509"
"Giai3" => "51911-02858"
"Giai4" => "14102-97270-96025-08465-89047-45904"
"Giai5" => "7892-9140-4069-8499"
"Giai6" => "6117-7471-5541-9119-4855-0566"
"Giai7" => "843-860-023"
"Giai8" => "71-13-55-89"
"Giai9" => ""
"Status" => "1"
]
數組我有一個int變量$position = 59
,而我的工作是由0
從Giai1 to Giai9
計數字符59 times
計發現價值並且得到該位置的值不包括字符-
,因此如果$position = 59
則位置58
處的得到的值將返回。
例如,在20
位置發現價值,回報是1 at 14102 in Giai4 (actually 19 count from 0)
我已經寫了這個代碼來做到這一點
$position = 59;
$count = 0;
foreach ($data['result'][0] as $key => $item)
{
if(preg_match('@[email protected]', $key))
{
$_item = str_replace('-', '', $item);
$count = $count + strlen($_item);
$chars = str_split($item);
$chars_sp = array_count_values($chars);
$countChar = count($chars);
if($count > $position)
{
//this block contains needed position
$math = $count - $position;
$secmath = strlen($_item) - $math;
for($i=$secmath;$i>=0;$i--){
if($chars[$i] == '-'){
$splash_last++;
}
}
$secmath = $secmath + $splash_last;
if($chars[$secmath] == '-'){
echo "+1 - ";
$secmath = $secmath + 1;
}
echo "Count: $count Match: $math Secmatch: $secmath Splash_last: $splash_last";
$chars[$secmath] = 'x' . $chars[$secmath] . 'y';
$edited = implode('', $chars);
$data['result'][0][$key] = $edited;
break;
}
}
}
dd($data['result'][0]);
}
預期結果將返回數組與getted號的標記。 例如,在59 (58 from 0)
位置找到的代碼爲x
,在y
結束時對其進行了標記。您可以在Giai5
//This is expected result
//Result array with mark of value at needed position
array:32 [▼
"ID" => "7917"
"ProvinceCode" => "MB"
"Create" => "2016-05-18 18:16:26.790"
"DayOfTheWeek" => "4"
"Giai1" => "28192"
"Giai2" => "83509"
"Giai3" => "51911-02858"
"Giai4" => "14102-97270-96025-08465-89047-45904"
"Giai5" => "7892-9140-x4y069-8499"
"Giai6" => "6117-7471-5541-9119-4855-0566"
"Giai7" => "843-860-023"
"Giai8" => "71-13-55-89"
"Giai9" => ""
"Status" => "1"
]
從1到50,它工作正常看到這一點,但位置50後的位置我得到的價值永遠是錯的
任何想法?
這是什麼點 - 你將如何使用這些標記? – splash58
@ splash58很難告訴你爲什麼我需要那個,但我需要那個。 – vietnguyen09