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