Home  >  Article  >  Backend Development  >  How to include other arrays in an array in php?

How to include other arrays in an array in php?

WBOY
WBOYOriginal
2016-08-04 09:20:491787browse

<code>        $name1=$_POST['name'];
        $hobbyS1=array();
        $hobbyS1=$_POST['hobbyS'];
        $sre1=$_POST['sre'];

        $fields = array($name1,$sre1);
        echo implode($fields);</code>

As shown in the above code, it displays normally.
I want to put the array hobbyS1 into $fields. How can I achieve this?
This is what I do
$fields = array($name1,$sre1,$hobbyS1);
No,
how should I put it? Thank you

Reply content:

<code>        $name1=$_POST['name'];
        $hobbyS1=array();
        $hobbyS1=$_POST['hobbyS'];
        $sre1=$_POST['sre'];

        $fields = array($name1,$sre1);
        echo implode($fields);</code>

As shown in the above code, it displays normally.
I want to put the array hobbyS1 into $fields. How can I achieve this?
This is what I do
$fields = array($name1,$sre1,$hobbyS1);
No,
how should I put it? Thank you

How to include other arrays in an array in php?

<code>var_dump($_POST)   看下有没有值,正常是可以的
</code>

$fileds = array($name1, $sre1); can be used after

<code>array_push($fileds, $hobbyS1); 
OR
$fields[] = $hobbyS1
</code>

How to include other arrays in an array in php?

After execution:

<code>$fields = array($name,$sre1);</code>

Use:

<code>$fields[] = $hobbyS1;
</code>

I tried it and it works

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn