Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nesting functions in PHP

Tags:

php

Simple PHP question:

Why does this work,

$exclude_exts = array('js', 'css',);
$filename = "test.css";
$ext = explode('.',$filename);
$is_excluded = in_array(strtolower(array_pop($ext)), $exclude_exts);

but this doesn't.

$exclude_exts = array('js', 'css',);
$filename = "test.css";
$is_excluded = in_array(strtolower(array_pop(explode('.',$filename))), $exclude_exts);

Edit: Both used to work in a previous version of PHP (I forgot which version).

like image 210
Ameer Avatar asked Jul 23 '13 13:07

Ameer


1 Answers

Because array_pop requires a reference, since it alters the array in place. When you pass the return value of explode there is no variable there to reference.

like image 178
Alexander Olsson Avatar answered Sep 24 '22 16:09

Alexander Olsson