PHP code example of spatie / query-string

1. Go to this page and download the library: Download spatie/query-string library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

spatie / query-string example snippets


# / > /?toggle

$queryString->toggle('toggle');

# / > /?single=a

$queryString->toggle('single', 'a');

# /?single=a > /?single=b

$queryString->toggle('single', 'b');

# /?single=a > /?

$queryString->toggle('single', 'a');

# / > /?multi[]=a&multi[]=b

$queryString->toggle('multi[]', 'a');
$queryString->toggle('multi[]', 'b');

# /?multi[]=a&multi[]=b > /?multi[]=a

$queryString->toggle('multi[]', 'b');

# / > /?filter[field]=a

$queryString->filter('field', 'a');

# / > /?filter[field][]=b

$queryString->filter('field[]', 'b');

# / > /?sort=field > /?sort=-field > /?sort=field

$queryString->sort('field');
$queryString->sort('field');
$queryString->sort('field');

$queryString->page(10); # /?page=10
$queryString->nextPage(); # /?page=11
$queryString->previousPage(); # /?page=9
$queryString->resetPage(); # /?

$queryString->isCurrentPage(1); # true

$queryString->withBaseUrl('https://other.url');

# /?toggle > /

$queryString->clear('toggle');

# /?single=b > /

$queryString->clear('single');

# /?multi[]=a&multi[]=b > /

$queryString->clear('multi[]');

# /?multi[]=a

$queryString->isActive('multi[]'); # true
$queryString->isActive('multi[]', 'a'); # true
$queryString->isActive('multi[]', 'b'); # false

# /?single=a

$queryString->isActive('single'); # true
$queryString->isActive('single', 'a'); # true
$queryString->isActive('single', 'b'); # false

# /?toggle

$queryString->isActive('toggle'); # true
 php
use Spatie\QueryString\QueryString;

$queryString = new QueryString($uri);