Menu
  • HOME
  • TAGS

Why does unset() change the way json_encode formats the string?

php,json,unset

json doesn't need to include the keys for a contiguous key sequence from offset zero. Unsetting a value from a standard enumerated array leaves a gap in the sequence of keys for that array, it doesn't adjust the remaining keys in any way; so the json needs to reflect this...

Javascript; unset a function?

javascript,function,unset

There's no need to unset it, since you might be needing it again in case the window size increases beyond 1024px. Here is a slightly optimized version of your code: function handleMargins() { var width = (window.innerWidth > 0) ? window.innerWidth : screen.width; if (width > 1024) { setTimeout(function ()...

How to keep some URL parameters and remove all others

php,unset

If parameters you want are always the same (I mean, keys are the same), then just do this: $myWantedParams = array('first' => $params['first'], 'second' => $params['second'] ... ); unset($params); Instead of thinking how to remove parameters, just focus on what you really need and take it. ...

PHP several ways to reset a variable

php,string,variables,null,unset

$resetME = null; -- wouldn't erase var from memory unset($resetME); -- erase var from memory $resetME = 0; -- wouldn't erase var from memory To completely remove a variable from memory you need to use unset. All other ways just change variable value But if variable wouldn't exists, you'll receive...

Use unset() to save memory

php,memory-management,unset

You can do this without temporary variable $countriesCovered[] = [ 'name' => $countryTag->getElementsByTagName('name')->item(0)->nodeValue, 'code' => $countryTag->getElementsByTagName('code')->item(0)->nodeValue ] ...

PHP: remove element from multidimensional array (by key) using foreach

php,arrays,multidimensional-array,foreach,unset

easy way!? you can do this just with one foreach! foreach ($data as $key => $subArr) { unset($subArr['1']); $data[$key] = $subArr; } ...

how to unset the item in $_SESSION array

php,session,unset

The following code would simply solve your problem: function DeleteProduct($pid) { foreach ($_SESSION['products'] as $key => $product) { if ($pid === $product['product_id']) { unset($_SESSION['products'][$key]); } } } But to make your work alot easier in the future you could also build your array like this: $_SESSION['products'] = array( 'product_id' =>...

Clearing a struct variable for re-assigning

c,variables,struct,unset

The variable currentlPulseSet is living on the stack. When it goes out of scope it will be removed from memory automatically. You don't have to do anything.

why is unset array value acting unexpected?

php,arrays,unset

If you had errors being displayed, you would see "undefined constant standard_rate, assuming 'standard_rate'". A string. Clearly, "standard_rate" == 25.00 is false. if( $return['standard_rate'] == 25) unset($return['standard_rate']); ...

Using unset() while iterating over array to remove empty values

php,arrays,unset

This should work for you: <?php $values_arr = array( 0 => "Text", 1 => "", 2 => "", 3 => "Text", 4 => "", 5 => "Text" ); foreach($values_arr as $k => $v) { if(empty($v) || $v == "") unset($values_arr[$k]); } print_r($values_arr); ?> Output: Array ( [0] => Text [3]...

Remove array element based on its character length

php,arrays,unset,strlen,array-unset

You can simply use it using array_filter only along with strlen $array = array("Linda","Chadwick","Bari","Angela","Marco"); $result = array_filter($array,function($v){ return strlen($v) > 4; }); print_r($result); $result = array(); array_walk($array,function($v) use (&$result){ if(strlen($v) > 4){$result[] = $v;} }); print_r($result); array_filter array_walk...

Session array unset and delete row

php,arrays,session,unset

Replace $_SESSION['c'] = $_SESSION['c'] -1; by $_SESSION['c'] = array_values($_SESSION['c']); "-1" will throw error since you are trying to subtract numeric value from a N-dimensional array. array_values will return you updated $_SESSION['c'] after unset/delete operation is done. P.S. Update your code accordingly for $_SESSION['cart'] as well....

How can I delete my undefined indexes in the array and move the others to position 0?

php,arrays,unset,undefined-index

You could use array_values() to reindex the array: unset($array[0]); $array = array_values($array); ...

Using unset() to delete node in XML; PHP/simplexml_load_file

php,arrays,xml,unset

SimpleXML is fine, no need to switch to DOM, unset() is working fine, if you do it right: unset($theUser[0]); see it working: https://eval.in/228773 However there will be a problem with your foreach() if you delete a node mid-loop. I suggest to use xpath() instead of a loop, IMO elegant and...

How can I traverse a multi level php object and unset the deepest node dynamically

php,object,unset

Without an example of what you actually have, I'm assuming you have an array of comments, and inside of each comment could be an array of more comments inside the comments field. If this is the case you would be doing something along the lines of unset($object->comments[1]->comments[2]->comments[3]); This would unset...

Mongodb $unset leaves empty array object(javascript)

javascript,node.js,mongodb,unset

If you really want to unset it first and then pull the element(s) missing key off the array use: db.test.update( { "_id": 1 }, // you can also use { } to clean up the whole collection { $pull: { "list": { "key": {$exists: false} } } } ) But...

Unsetting PHP session variable doesnt display error message

php,session,unset

Try not reloading the same page.. remove the header redirect. if ($result = $sth->fetch(PDO::FETCH_ASSOC)){ $_SESSION['admin_user'] = $result['id']; header('Location: admin_user.php'); } else { $_SESSION['user_found'] = 0; //header('Location: index.php'); } ...

XML if unset node cant get variable value

php,xml,variables,foreach,unset

SimpleXML is an abstraction for the DOM. $child and $child[0] are separate SimpleXMLElement objects, but access the same DOM node. The unset() not just deletes the SimpleXMLElement object, but removes the node from the DOM, too. So after that the second SimpleXMLElement objects refers to a removed DOM node. With...

Unsetting array value in foreach loop with session?

php,session,foreach,unset

I solved my question by doing the below: elseif (mysql_num_rows($results)>= 1) { echo "Customer: ". $customer. "<br>Active workcard:<br>"; $task_array = array_combine($task_id_unique, $task_status); foreach ($task_array as $card_nr => $card_status) { ?> <?php if ($card_status == true) { echo "<table><tr>"; echo "<th>Workcard nr.</th>"; echo "<th>Status</th></tr>"; echo "<td>".$card_nr."</td>"; echo "<td>"; echo "<form action='workcard_open.php'...

how to clear the field form after success without redirect to another page in codeigniter

forms,codeigniter,clear,unset

try like this <input type="text" name="name" class="input-block-level" placeholder="Name" required maxlength="40" id="name" /> $.post(faction, fdata, function(rdata) { var json = jQuery.parseJSON(rdata); if (json.isSuccessful) { $('#successMessage').html(json.message); $('#success').show(); $('#name').val(''); // add this line } else { $('#errorMessage').html(json.message); $('#error').show(); } ...

PHP multidimensional array unset

php,multidimensional-array,unset,array-unset

This should work for you: (In this code i go trough each innerArray and each value & key from the innerArray. Then i simple check if it's the right key with the right value. If the condition is true i unset the entire array) <?php $_SESSION['array']= array(1=>array("surname"=>"foofoo", "name"=>"foo"), 2=>array("surname"=>"foofoo2", "name"=>"foo2"));...

PHP Unsetting values in another array with identical key

php,arrays,foreach,unset

What exactly are the keys in the arrays? Because, you cannot have every key in an array be the same. They overwrite each other. (Not sure if this is just for your example or not). Anyway, using this code works, with tests to verify... <?php $list = array( 2,3,4,5,6 );...

using (unset) for multiple parameters

php,unset

$params['qdef'] and $params['qval1'] are separate elements in the array use unset($params['qdef'], $params['qval1']); to unset them individually unset($params['qdef, qval1']); is trying to unset a single element from $params with a key of 'qdef, qval1'...

How to delete or unset a cookie when the browser is closed?

php,cookies,unset

Specify time = 0 or blank , when you do so, the cookie will expire as the browser is closed. setcookie( 'site', $_GET['site'], 0, COOKIEPATH, COOKIE_DOMAIN); The cookie will not expire if only the tab is closed and not the browser....

Shorten code for removing array element with conditional in php pdo

php,arrays,pdo,unset

$query = $db->prepare($sql); $array = array(':page_parent' => $parent_id, ':page_active' => $active); //array_filter will remove null and false array element $array = array_filter($array); $query->execute($array); ...

Unset certain items from session array when they're clicked?

php,html,arrays,session,unset

Its possible, you'll need to handle that request as well. If you want the click posted, a simple <button> next to that should suffice. Upon rendering the markup, (of course using the session array) use the key which can be used in unsetting the values. <?php // initialization if(empty($_SESSION['user_playlists'])) {...

Delete from JSON with PHP

php,json,rest,unset

Inside a foreach-loop the copy of the array element you've got does not affect the original array in some ways. You need to dereference the array item using the original array or pass it to the loop by reference. The following should work, I guess: if($id){ header('Content-Type: application/json'); $id =...

Drupal 7 alter node display

drupal-7,field,alter,unset

I found the answer to my question. The node object contains an array called content which is the renderable data Drupal will print to screen. It's in that array that my unsets need to take place. I.E: unset($node->content['field_main_picture']); And the main picture image disappears....

Rearrange array index Eloquent Laravel

php,arrays,json,laravel,unset

I have found a solution in the laravel documentation. after modifying the array, you have to call a method from laravel collection named values() that arrange the array indexes, example: unset($property->rooms[$key]); $property->rooms->values(); ...