Edmond Tamas Edmond Tamas - 5 months ago 7
PHP Question

Php explode() - "expects parameter 2 to be string, array given", while param 2 is a string

Could somone please tell me why is explode() is complaining about my second parameter which basically is a string?

$params = ['pag'=>'0-100'];
echo gettype(); // it says string

$pagination = explode('-', empty($params['pag']) ? DEFAULT_PAGINATION : $params['pag']);


Exception:


PHP Warning: explode() expects parameter 2 to be string, array given

Answer

I get a different result.

<?php
$params = ['pag'=>'0-100'];    
//echo gettype(); // it says string

$pagination = explode('-', empty($params['pag']) ? '1' : $params['pag']);
var_dump( $pagination );

result : array(2) { [0]=> string(1) "0" [1]=> string(3) "100" }

What's your PHP version?

Comments