Access array returned by a function in php

前端 未结 5 565
抹茶落季
抹茶落季 2020-11-22 12:43

I\'m using a template engine that inserts code in my site where I want it.

I wrote a function to test for something which is quite easy:

myfunction()         


        
5条回答
  •  执笔经年
    2020-11-22 12:47

    It is possible from PHP version 5.4.

    If you don't want a temporary variable for that and your PHP version is less, than 5.4, than you still can use a few built in functions to get the first or the last element:

    $x     = 'first?last';
    $first = array_shift(explode('?', $x));
    $last  = end(explode('?', $x));
    $last2 = array_pop(explode('?', $x));
    

    Edit: !!! Please note, that in later versions( 5.4+ ) PHP will throw a notice, because end only expects variables as parameter.

提交回复
热议问题