array_push将不给出数组,打印出整数值 [英] array_push won't give an array, prints out integer value

查看:110
本文介绍了array_push将不给出数组,打印出整数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用array_push做一个非常简单的php程序,但是根据文档,它不起作用.每次我尝试打印最终数组的值时,它都会给我一个整数.有人可以帮我吗?

I'm doing a very simple php program with array_push, but it isn't working according to the documentation. Every time i try to print the value of the final array, it gives me an integer. Could someone please help me with this?

这是我的代码:

<?php
    $preArray = array('1','2','3','4','5','6','7','8');
    $val = 10;
    $array = array_push($preArray, $val);

    print_r($array);
?>

这是它的输出:

9

预先感谢您的帮助.

推荐答案

array_push()返回数组中新的元素数.因此,如果您对数组中的元素数量不感兴趣,则只需使用:

array_push() returns the new number of elements in the array. So if you're not interested in the number of elements in the array then just use:

array_push($preArray, $val);

变量$ preArray将包含推入其中的值.

The variable $preArray will contain the value pushed into it.

print_r($preArray);

这篇关于array_push将不给出数组,打印出整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆