homepage Welcome to WebmasterWorld Guest from 54.227.12.219
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Quick Question regarding: Only variables should be passed by reference
tec4




msg:4493876
 4:41 pm on Sep 11, 2012 (gmt 0)

Just want to better understand why I'd be getting this error:

Strict Standards: Only variables should be passed by reference in /directory...


$to_email = Array();
foreach($_POST as $key => $value) {
if(stripos($key, "contact_") === 0) {
$id = array_pop(explode("_", $key));
$to_email[] = $id;
}
}



But when I change it to the below code, it works fine

$to_email = Array();
foreach($_POST as $key => $value) {
if(stripos($key, "contact_") === 0) {
$id = explode("_", $key);
$id = array_pop($id);
$to_email[] = $id;
}
}


Is it as simple as you are not supposed to modify a string or value from it's original form without actually storing it as it's 'new' value?

 

lostdreamer




msg:4494621
 7:36 am on Sep 13, 2012 (gmt 0)


$id = array_pop(explode("_", $key));


There's your problem ;)

explode will return an array.
Array_pop will take that array, and remove the last value from it.

But since you are not supplying Array_pop with an array (but rather a function that returns an array) it cannot modify the array for you.


[php.net...]

tec4




msg:4495570
 8:57 pm on Sep 15, 2012 (gmt 0)

Haha thanks :P

Ya, that makes sense. Just hadn't really toyed much with this stuff I guess - but your explanation cleared it up. Much appreciated!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved