The Little Guy Posted April 17, 2009 Share Posted April 17, 2009 OK, I have an explode, is there any way to get the third value of the array using one line of code, kind of like this? return explode(':',$content)[2]; I know in some programming languages, you can do something similar to this. Link to comment https://forums.phpfreaks.com/topic/154552-arrays/ Share on other sites More sharing options...
soak Posted April 17, 2009 Share Posted April 17, 2009 I'm pretty sure there's not, I think you need to assign it first. I know that array_pop, push etc don't like running on an explode. Link to comment https://forums.phpfreaks.com/topic/154552-arrays/#findComment-812692 Share on other sites More sharing options...
Maq Posted April 17, 2009 Share Posted April 17, 2009 $p = explode(':',$content); return $p[2]; One line... Link to comment https://forums.phpfreaks.com/topic/154552-arrays/#findComment-812696 Share on other sites More sharing options...
Philip Posted April 17, 2009 Share Posted April 17, 2009 It's not practical, but in one line (not cheating like Maq ) return implode(array_slice(explode(':',$content),2,1)); Link to comment https://forums.phpfreaks.com/topic/154552-arrays/#findComment-812718 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.