note 116791 added to function.http-build-query

From: Date: Sun, 01 Mar 2015 10:41:18 +0000
Subject: note 116791 added to function.http-build-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-201828@lists.php.net to get a copy of this message
As noted, this function omits keys with null values. This could break some code which treats the key as boolean, and so has no value, or other code expecting the array to be populated regardless of value. A workaround for this is to replace the null values with an empty string: $data=array( 'a'=>'apple', 'b'=>2, 'c'=>null, 'd'=>'…', ); // Compensate for fact that http_build_query omits null values foreach($data as &$datum) if($datum===null) $datum=''; Losing the null-ness of the original is no real loss if it’s supposed to be a real query string. If the null is important, you could use a dummy value instead. Mark ---- Server IP: 72.52.91.14 Probable Submitter: 27.32.215.64 ---- Manual Page -- http://php.net/manual/en/function.http-build-query.php Edit -- https://master.php.net/note/edit/116791 Del: integrated -- https://master.php.net/note/delete/116791/integrated Del: useless -- https://master.php.net/note/delete/116791/useless Del: bad code -- https://master.php.net/note/delete/116791/bad+code Del: spam -- https://master.php.net/note/delete/116791/spam Del: non-english -- https://master.php.net/note/delete/116791/non-english Del: in docs -- https://master.php.net/note/delete/116791/in+docs Del: other reasons-- https://master.php.net/note/delete/116791 Reject -- https://master.php.net/note/reject/116791 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#201828) next »