dongyun51582 2013-11-01 00:00
浏览 24
已采纳

PHP数组声明问题

$info = array(
        "First_Names" => "John",
        "Last_Names" => "Smith",
        "Gender" => "Male",
    );

array_push($info["First_Names"], "$fname");

print_r ($info);

I started learning PHP through a high school class. I'm not exactly knowledgeable nor do I pay attention much, but I'm completely stuck on this;

What I'm trying to do is get the variable $fname which is defined by the user (Jack, James, Shelly, etc) to be pushed into the array First_Names which is inside the array of $info. I'm not sure where it's going wrong, but PHP is not declaring $info as an array (I think, it states "Warning: array_push() [function.array-push]: First argument should be an array in /home/a4938424/public_html/process.php on line 22". If I print out the array it will show up the default names and gender,and if I echo out the $fname variable it shows up properly.)

I've consulted two different people and neither of their suggestions worked, now I'm stumped completely and everyone is out of suggestions. Does anyone see what's going on with it? Thanks for any responses, please be aware that I barely know any PHP.

  • 写回答

4条回答 默认 最新

  • dongsu3654 2013-11-01 00:02
    关注

    $info['First_Names'] is not an array, it is a string ("John"). If you define it as an array, it might work ;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?