0

I am working with php and phpexcel,I have following array($data) i want to search and append array value in php,For example i want to change "link" value(want to add "txt" with previous value) of user whose email id is "[email protected]",But its not working properly, i mean after refresh page , its removing previous "appended" value and append current value,but i want keep previous value also,Ho can i do this ? Here is my current array

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

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

Expected result (adding "bbb" instead of removing "abb")

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

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

I tried with following code but "removing" previous value ("abb"),i want to append new value with previous

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

1 Answer 1

1

I have the same error yesterday and same mistake as you have done here. Try this code

$searchEmail = '[email protected]';
$appendString = 'bbb';
foreach ($set_excel_query_all as $key => $item) {
if ($item['email'] == $searchEmail) {
  $set_excel_query_all[$key]['link'] .= ',' . $appendString;
  break;
}
}
unset($item);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.