Questions tagged [array-unset]

44 questions
0
votes
1 answer

Exclude an ID from array in PHP

How can I exclude a certain ID being pulled from an array on the below? id; ?> The array is pulling all ID's but I want to exclude a specific one and include the rest. Would it be by using unset to remove the specific ID?
RonnieT
  • 2,193
  • 4
  • 32
  • 43
0
votes
1 answer

How to delete all the values from the mixed array in php?

I have one array which is mixedtype both associative and indexed based elements, i want to remove all the values and keys from the array and make that array as empty,i tried unset function but it's not removing last element of the array, can you…
usersuser
  • 167
  • 12
0
votes
1 answer

PHP remove multiple array key inside an array with multiple values

I find I can't figure out the desired output. I have JSON raw data contains this: Array ( [data] => Array ( [0] => Array ( [title] => currency1 [tickers] =>…
0
votes
3 answers

How to remove all specific keys from an associative array PHP

I have to unset all 'priority' keys and values from an associative array like the one below. Couldn't find yet a solution to do this. Which do you think is the best method to remove a specific key-value pair from an entire array? $countries =…
0
votes
1 answer

unset not deleting key in multidimensional array

I have multidimensional array and wants to remove delivery location where ever it exists Array ( [0] => Array ( [amountReceived] => 1 [deliveryLocation] => germany ) [1] => Array ( …
Mohsin
  • 179
  • 4
  • 13
0
votes
2 answers

PHP: Delete Array from 2D-Array

I am uploading a CSV file/report with 10 columns but at the end of the CSV file there are a few lines that just give details about the report like Generated By: XXX Company Name Report Run @ 2019-03-14 When I load the array, the keys are just…
Bijan
  • 7,737
  • 18
  • 89
  • 149
0
votes
2 answers

Efficient way to remove key-value from Array of Arrays

I have an array of 50000 arrays and i want to remove the "id" key-value pair from each of them. I would rather not loop through 50k elements and was wondering if there was an efficient way to do it. Array ( [0] => Array ( …
Sam.tuver
  • 679
  • 2
  • 9
  • 19
0
votes
2 answers

change original array values inside foreach php

I want to update an array inside foreach I tried this two code : code 1 : foreach ($listOrders as $k => $order) { foreach ($listOrders as $key => $o) { if ($o["id_order"] == $order["id_order"]) { …
Sabra
  • 177
  • 2
  • 19
0
votes
2 answers

Php Json Array Unset Not Working

array(1) { ["value"] => array(1000) { [0]=> array(9) { ["PartitionKey"]=> string(11)"AWT-GPI.com" ["RowKey"]=> string(36) "0024a6ac-6cf1-454a-91b2-15bfec3a3d86" ["Timestamp"]=> string(28) "2016-09-09T20:16:26.8674483Z"…
Alex Rieker
  • 93
  • 2
  • 8
0
votes
3 answers

PHP Iterate through multidimensional Array, count Strings inside and unset based on count

I want to iterate over a multidimensional array, count the occurrences of a String inside and delete Array items where the count is higher than e.g. 3. I've already tried a pretty messy combination of array_search, array_count_values and strpos…
0
votes
1 answer

PHP 5.6 unset $_SESSION sub array entry

I got the following function: public function stopWatcherSession($sessionID) { if(array_key_exists($sessionID, $_SESSION[self::WATCHER_SESSION_KEY])) { foreach ($_SESSION[self::WATCHER_SESSION_KEY][$sessionID]['names'] as $v) { …
beatjunky99
  • 149
  • 11
0
votes
2 answers

Remove array element based on its character length

I have an array in PHP as: $array = array("Linda","Chadwick","Bari","Angela","Marco"); Therefore, $array[0]="Linda" $array[1]="Chadwick" $array[2]="Bari" $array[3]="Angela" $array[4]="Marco" I want to remove the names having string…
Saif
  • 2,530
  • 3
  • 27
  • 45
0
votes
1 answer

Remove multiple elements from array and reindex

Can I remove the first three elements and all the remaining ones where value is not equal to 2? The language is php. print_r($array) outputs Array ( [0] => Array ( [name] => aa [value] => 0 ) [1] => Array ( [name] => db [value] =>…
sweet potato
  • 135
  • 1
  • 11
0
votes
6 answers

Remove every nth item from array

I want to unset every second item from an array. I don't care about if the keys are reordered or not. Of course I want it fast and elegant. Is it maybe possible without a loop and temporary variables?
flori
  • 14,339
  • 4
  • 56
  • 63
0
votes
1 answer

advanced unset the value form array PHP

I have two arrays, what consist arrays. I need to merge these arrays recursive. But I need to do this action few times, and array_merge_recursive() will apend my data twice, I want to remove element what already exist in target array. $messages…
nowiko
  • 2,507
  • 6
  • 38
  • 82