Questions tagged [array-unset]

44 questions
10
votes
5 answers

Removing key => value pairs from an array, but its not removing them

I am trying to remove two key value pairs from an array, I am using the code below to segregate out the keys I don't want. I don't understand why it is not equating properly. if I remove the OR (|| $key != 6) it will work properly but I was hoping…
Drewdin
  • 1,732
  • 5
  • 23
  • 35
8
votes
5 answers

php elegance keys unsetting

I need to remove from an array some keys. $array = array('a' => 'a', 'b' => 'b', 'c' => 'c'); unset($array['a']); unset($array['b']); How can I do this more elegance? Maybe there is a function like this array_keys_unset('a', 'b')?I don't need…
Alex Pliutau
  • 21,392
  • 27
  • 113
  • 143
4
votes
6 answers

json with no index after unset encode array in php

I hope anyone can help me. My JSON isn't indexed (i.e. there isn't any key above any element) [ { "nome":"LABORGHINI GALLARDO", "descrizione":"LAMBORGHINI GALLARDO ED. NERA- ANNO 2007- ", "indirizzo_pubblicato":"autocaricateeea\/LABORGHINI…
Manuel Ragazzini
  • 919
  • 1
  • 10
  • 24
3
votes
2 answers

Removing arrays from multi dimension array based on single values

I am trying to filter a multi-dimension array by removing subarrays where the permission value is no. My array: $array = array( array( 'name' => 'dashboard', 'permission' => 'yes' ), array( 'name' => 'Purchase…
Adam Lambert
  • 1,311
  • 3
  • 24
  • 45
3
votes
2 answers

Remove keys from a multi-dimensional array when some specific values are matching the given array

I'm sure I'm only facing a logical problem here. I have an array like this : var_export($myarray); array ( 0 => array ( 'inf:name' => 'aaa', 'inf:value' => '111', 'inf:children' => NULL, ), 1 => array ( 'inf:name' =>…
Cybrix
  • 3,248
  • 5
  • 42
  • 61
2
votes
5 answers

PHP array unset

Here code (executed in php 5.3.5 and 5.2.13): $res = array(1, 2, 3); unset($res[0]); for($i = 0; $i < sizeof($res); $i++) { echo $res[$i] . '
'; } In results i see
2
Why only one element, and first empty? Can`t understand.…
swamprunner7
  • 1,321
  • 6
  • 16
  • 25
2
votes
3 answers

How to unset array inside array

I have an array in the following structure Array ( [members] => Array ( [0] => Array ( [nr] => 2 [email] => email1 ) [1] => Array ( [nr] => 6 [email] => email2 ) [2] => Array ( [nr] => 3 [email] => email3 ) ) [title] => List…
Dobi Caps
  • 57
  • 1
  • 8
2
votes
2 answers

Divide Array Items To Anothe Array Equally In Random Order Php

The title is pretty much self-explanatory so I will go straight to the problem. Let's assume I have an array of some items like this: $classicRoles = [ 'mafia', 'mafia', 'don', 'civilian', 'civilian', 'civilian', …
Volo Apps
  • 235
  • 1
  • 3
  • 12
2
votes
2 answers

Unsetting several indexes starting with a predetermined prefix

I have an array that looks like this: Array ( [game.info.campaign.end_date] => 2016-07-31, [game.info.campaign.start_date] => 2016-07-11, [game.info.campaign.peak_date] => 2016-07-21, [game.info.campaign.promo] => 'pokemon_go' ); I would like to…
dms
  • 129
  • 1
  • 1
  • 8
2
votes
2 answers

Why doesn't this for loop seem to execute although the condition is still true?

In the following SSCCE, why isn't the for loop being executed for $a greater than 3, although the condition should let it execute till $a becomes 5. And the output of the last statement is even more weird. What I am trying to achieve is that I want…
Solace
  • 8,612
  • 22
  • 95
  • 183
2
votes
5 answers

PHP: unset $_SESSION of array

I have a session of arrays named: $_SESSION['A']; it contains $_SESSION['A'][0] = 'A'; $_SESSION['A'][1] = 'B'; I can unset the $_SESSION['A']; using unset($_SESSION['A']); it unset all the value in the array how can I unset all value stored in…
Detention
  • 167
  • 1
  • 1
  • 10
1
vote
1 answer

Disable payment methods based on WooCommerce cart total

I tried this code below to hide/disable Credit/Debit card and Direct bank transfer payment method on Woo commerce(WordPress) when the checkout total == 400 but did not work. Please any idea on how to achieve this? Thank you so kindly. function…
1
vote
1 answer

Delete an array element based on value from nested array

I have try to remove whole parent array using PHP unset(key) function based on value from a nested array in it. Nested array looks like Array ( [0] => Array ( [ID] => 9909 [SHIPPING_AMOUNT] => 5 [TOTAL_TAX] => 0 [GRAND_AMOUNT]…
JackTheKnife
  • 3,795
  • 8
  • 57
  • 117
1
vote
1 answer

loop through multidimensional array and order sub-array by scores

I am trying to calculate the winning order of golfers when they are tied in a competition. These golf competitions are using the "stableford" points scoring system, where you score points per hole with the highest points winning. Compared to normal…
Dan Burt
  • 47
  • 1
  • 7
1
vote
1 answer

PHP multidimensional array unset

I have a multidimensional array of the structure : $_SESSION['array'] = array(1=>array("surname"=>"foofoo", "name"=>"foo"),2=> .... so on); I want to delete an entry if the surname matches a given variable e.g $surname = "foofoo"; the function…
mrahmat
  • 617
  • 6
  • 21
1
2 3