Issue with not being able to append value using Php in loop
P粉478835592
P粉478835592 2023-09-13 21:24:02
0
1
502

I'm using php and phpexcel, I have the following array ($data), I want to search and append the array value in php, for example, I want to change the user's "link" value (want to append after the previous value "txt") whose email id is "cde@gmail.com" but it is not working properly, I mean after refreshing the page it removes the previous "append" value and appends the current value but I want to keep What should I do with the previous value? This is my current array

Array ( [0] => Array ( [email] => abc@gmail.com [link] => abc,xyz,def ) [1] => Array ( [email] => cde@gmail.com [link] => cde,abb ) ...

Desired result (adding "bbb" while removing "abb")

Array ( [0] => Array ( [email] => abc@gmail.com [link] => abc,xyz,def ) [1] => Array ( [email] => cde@gmail.com [link] => cde,abb,bbb ) ...

I tried the following code, but it will "delete" the previous value ("abb"), and I want to append the new value to the previous value

$searchEmail = 'cde@gmail.com'; $appendString = 'bbb'; foreach ($set_excel_query_all as $key => &$item) { if ($item['email'] == $searchEmail) { $item['link'] .= ',' . $appendString; break; } } unset($item);

P粉478835592
P粉478835592

reply all (1)
P粉098417223

I ran into the same error yesterday as you did here. Try this code

$searchEmail = 'cde@gmail.com'; $appendString = 'bbb'; foreach ($set_excel_query_all as $key => $item) { if ($item['email'] == $searchEmail) { $set_excel_query_all[$key]['link'] .= ',' . $appendString; break; } } unset($item);
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!