API15

JURI/buildQuery

From Joomla! Documentation

< API15:JURI
Revision as of 17:19, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Build a query from a array (reverse of the PHP parse_str()) <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JURI/buildQuery|Edit De...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Build a query from a array (reverse of the PHP parse_str())

[Edit Descripton]

Template:Description:JURI/buildQuery

Syntax[edit]

buildQuery($params, $akey=null)
Parameter Name Default Value Description
$params
$akey null

Returns[edit]

string The resulting query string

Defined in[edit]

libraries/joomla/environment/uri.php

Importing[edit]

jimport( 'joomla.environment.uri' );

Source Body[edit]

function buildQuery ($params, $akey = null)
{
        if ( !is_array($params) || count($params) == 0 ) {
                return false;
        }

        $out = array();

        //reset in case we are looping
        if( !isset($akey) && !count($out) )  {
                unset($out);
                $out = array();
        }

        foreach ( $params as $key => $val )
        {
                if ( is_array($val) ) {
                        $out[] = JURI::buildQuery($val,$key);
                        continue;
                }

                $thekey = ( !$akey ) ? $key : $akey.'['.$key.']';
                $out[] = $thekey."=".urlencode($val);
        }

        return implode("&",$out);
}

[Edit See Also] Template:SeeAlso:JURI/buildQuery

Examples[edit]

<CodeExamplesForm />