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

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 "[email protected]" 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] => [email protected]
            [link] => abc,xyz,def
         )

    [1] => Array
        (
            [email] => [email protected]
            [link] => cde,abb
        )
...

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

Array
(
    [0] => Array
        (
            [email] => [email protected]
            [link] => abc,xyz,def
         )

    [1] => Array
        (
            [email] => [email protected]
            [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 = '[email protected]';
$appendString = 'bbb';
foreach ($set_excel_query_all as $key => &$item) {
   if ($item['email'] == $searchEmail) {
      $item['link'] .= ',' . $appendString;
      break;
   }
}
unset($item);

P粉478835592
P粉478835592

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!