FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » How to convert this PHP into JavaScript
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: How to convert this PHP into JavaScript [message #173181 is a reply to message #173180] Sat, 26 March 2011 12:04 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
Senior Member
Jerry Stuckle wrote:

> Thomas 'PointedEars' Lahn wrote:
>> sheldonlg wrote:
>>> Thomas 'PointedEars' Lahn wrote:
>>>> Denis McMahon wrote:
>>>> > Oltmans wrote:
>>>> >> […] Here is the PHP
>>>> >>
>>>> >> array(
>>>> >> 'abc' => '1 AND (2 OR
>>>> >> 3)', // Define how to
>>>> >> use the following criteria
>>>> >> 'def' => array('marketing_campaign_id', 'status',
>>>> >> 'status'), // Filter by these three criteria
>>>> >> 'ghi' => array('eq', 'eq',
>>>> >> 'eq')
>>>> >> );
>>>> >>
>>>> >> I need to convert above into JavaScript object which looks like
>>>> >>
>>>> >> {
>>>> >> 'abc' : '1 AND (2 OR 3)'
>>>> >> }
>>>> >> […]
>>>> > […]
>>>> <?php echo json_encode(array('abc' => '1 AND (2 OR 3)')); ?>
>>>> […]
>>> […]
>>> <?php
>>> $arr = array('abc'=>1, 'def'=>array('marketing_campaign_id', 'status',
>>> 'status'), 'ghi'=>array('eg', 'eq', 'eq'));
>>> $json = json_encode($arr);
>>> print '<pre>'; print_r($arr);print'</pre>';
>>> print 'json endoded = '.$json;
>>> ?>
>>>
>>> generates this output:
>>> Array
>>> (
>>> [abc] => 1
>>> [def] => Array
>>> (
>>> [0] => marketing_campaign_id
>>> [1] => status
>>> [2] => status
>>> )
>>>
>>> [ghi] => Array
>>> (
>>> [0] => eg
>>> [1] => eq
>>> [2] => eq
>>> )
>>>
>>> )
>>>
>>> json endoded =
>>> {"abc":1,"def":["marketing_campaign_id","status","status"],"ghi":
>>> ["eg","eq","eq"]}
>>>
>>
>> Your point being?
>>
>> <http://www.netmeister.org/news/learn2quote.html>
>
> Maybe that you are totally clueless, as always?

Maybe not, as the presented return value of json_encode() corresponds with
what the OP asked for; only that for some reason sheldonlg used 1 instead of
the '1 AND (2 OR 3)' of the OP. So much for cluelessness.

You want to learn to quote as well.


PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7(at)news(dot)demon(dot)co(dot)uk> (2004)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: website developers requirements
Next Topic: Aste - PHP template engine
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 21:59:05 GMT 2024

Total time taken to generate the page: 0.03613 seconds