unset

Unsetting index in array turns it to an object

ぃ、小莉子 提交于 2019-12-04 04:02:28
问题 So I have a JSON document I'm storing in CouchDB. Here's the important part of it: "games": { "creator": [ "cf86d68b24c1bbf22702356572027642", "cf86d68b24c1bbf22702356572027dd8", "cf86d68b24c1bbf22702356572028b77" ], "solver": { } } I'm trying to remove one item from the array, let's say index 1: error_log("pre unset: " . json_encode($user->games)); unset($user->games->creator[1]); error_log("post unset: " . json_encode($user->games)); The problem is, it keeps converting my array to an object

PHP | Remove element from array with reordering?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 03:44:30
How can I remove an element of an array, and reorder afterwards, without having an empty element in the array? <?php $c = array( 0=>12,1=>32 ); unset($c[0]); // will distort the array. ?> Answer / Solution: array array_values ( array $input ). <?php $c = array( 0=>12,1=>32 ); unset($c[0]); print_r(array_values($c)); // will print: the array cleared ?> array_values($c) will return a new array with just the values, indexed linearly. If you are always removing the first element, then use array_shift() instead of unset(). Otherwise, you should be able to use something like $a = array_values($a).

Recursive search and remove in array?

风格不统一 提交于 2019-12-04 03:43:58
问题 I am working with a multidimensional array I want to be able to remove an array (and all children) which match an id. The function I have tried is: function removeKey($key, $array, $childKey = 'children'){ if(isset($array[$key])){ unset($array[$key]); return $array; } foreach($array as &$item) if(isset($item[$childKey])) $item = removeKey($key, $item[$childKey], $childKey); return $array; } My example array is: Array ( [5] => Array ( [id] => 5 [parent_id] => [menu_title] => Drinks [page_title

How to delete an exact element in a bash array?

南楼画角 提交于 2019-12-03 08:22:57
I am trying to remove just the first appearance of any one keyword from a bash array. ARRAY=(foo bar and any number of keywords) keywords=(red, rednet, rd3.0) I remove the keyword like this: ARRAY=( ${ARRAY[@]/"$keyword"/} ) then if "red' is the first found keyword, it will strip ' red ' from both keywords and return "foo bar net" instead of "foo bar rednet". Edit: Here is example, hopefully this makes it clearer. for keyword in ${ARRAY[@]}; do if [ "$keyword" = "red" ] || [ "$keyword" = "rd3.0" ] || [ "$keyword" = "rednet" ]; then # HERE IS TROUBLE ARRAY=( ${ARRAY[@]/"$keyword"/} ) echo

How to remove column from child collection

泄露秘密 提交于 2019-12-03 07:24:49
问题 I have a collection in MongoDB called CrawlUser. It has a list called CrawlStatuses, which is a list of CrawlStatus objects. CrawlStatus has a property called LastErrorMessage which I want to remove from the collections. I tried to do the following to remove it but it didn't work... No error message given, but the LastErrorMessage column is still there. db.CrawlUser.update( {}, { $unset: { "CrawlStatuses.LastErrorMessage": 1 } }, false, true); Any ideas what I'm doing wrong? One other related

How to remove column from child collection

佐手、 提交于 2019-12-02 20:55:34
I have a collection in MongoDB called CrawlUser. It has a list called CrawlStatuses, which is a list of CrawlStatus objects. CrawlStatus has a property called LastErrorMessage which I want to remove from the collections. I tried to do the following to remove it but it didn't work... No error message given, but the LastErrorMessage column is still there. db.CrawlUser.update( {}, { $unset: { "CrawlStatuses.LastErrorMessage": 1 } }, false, true); Any ideas what I'm doing wrong? One other related question, if I do the $unset command on a column in a collection that is very large (millions of rows)

Yii - Manipulating a sesssion variable

和自甴很熟 提交于 2019-12-02 09:54:48
I am a still a newbie when it comes to using YII, but I been working with session variables for the past few days, and I can't seem to grasp to the concept behind my error. Any advice will be appreciated. My add function works perfectly so far, for my current purpose of keeping track of the last 3 variables added to my session variable nutrition. public function addSessionFavourite($pageId) { $page = Page::model()->findByPk($pageId); $categoryName = $page->getCategoryNames(); if($categoryName[0] == 'Nutrition') { if(!isset(Yii::app()->session['nutrition'])) { Yii::app()->session['nutrition'] =

batch script variable unset in for loop has no effect

懵懂的女人 提交于 2019-12-02 08:03:14
问题 Below is my script. I am trying to look into folders one level below and pick out only those folders, hence the ~-9 which extracts the last 9 chars from the path. But the set var= does not unset the variable because the output comes back with the same folder name repeated # times. Also batch doesn't allow me to do this extract trick directly on %%i, hence the need for the local variable. How do I clear this variable so that it takes the new value in the next iteration? @echo off for /d %%i in

Codeigniter session will not unset

荒凉一梦 提交于 2019-12-02 07:43:35
im working on a community, and i want to user to log off but it dosent unset the userdata :S, do you know why? this is my controller function function logOff() { //$this->session->flashdata('reports', 'Du er logget af'); //redirect('frontpage', 'refresh'); $this->session->unset_userdata($sessionData); } You can destroy an entire session by calling the following: $this->session->sess_destroy(); You need to specify what elements you want to unset individually rather than a variable or object as per your code: $this->session->unset_userdata($sessionData); Instead use to remove the login

batch script variable unset in for loop has no effect

断了今生、忘了曾经 提交于 2019-12-02 06:14:15
Below is my script. I am trying to look into folders one level below and pick out only those folders, hence the ~-9 which extracts the last 9 chars from the path. But the set var= does not unset the variable because the output comes back with the same folder name repeated # times. Also batch doesn't allow me to do this extract trick directly on %%i, hence the need for the local variable. How do I clear this variable so that it takes the new value in the next iteration? @echo off for /d %%i in (%1\*) do ( set var=%%i echo %var:~-9% set "var=" ) http://judago.webs.com/variablecatches.htm has an