Doubts about PHP array_unshift functions

Source: Internet
Author: User
Questions about the PHP array_unshift function
This post was last edited by Eiysxd on 2014-08-22 23:07:03

The Array_unshift function is to throw arguments to the front of the array, but why not?
$forums [$key] [' level '] + = 1;
I used the print_r to output
Array ([FID] = 2 [Fup] = 1 [name] + test [displayorder] = 0 [Threads] + 2 [posts] = 2 [todayposts] + 0 [Allparent] = = Array ([0] = 2) [Allnodes] = Array ([0] = 2) [level] = 1)

$fup = 1
Then this code array_unshift ($forums [$key] [' Parent '], $fup);

I'm looking at the Print_r output.
Array ([FID] = 2 [Fup] = 1 [name] + test [displayorder] = 0 [Threads] + 2 [posts] = 2 [todayposts] + 0 [Allparent] = = Array ([0] = 1 [1] + 2) [allnodes] = = Array ([0] + 2) [level] = 1 [Parent] =)

May I ask why the parent = is empty?? Isn't it supposed to be [Parent]=>array (0]=>1) like this??
------Solution--------------------
It is possible that the parent in the array was not found in the first attempt.

$fup =array (Array (' parent ' =>1));
Array_unshift ($forums [$key], $fup);

------Solution--------------------
Where is the $forums [$key] [' parent '] defined? Why didn't I see it?
Your Array_unshift ($forums [$key] [' Parent '], $fup); A Warning error will be generated:
Array_unshift () expects parameter 1 to is array, null given

But you're proud to reject PHP's help.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.