dongwen2162 2018-09-21 18:43
浏览 38
已采纳

PHP关联数组仅显示第一个字母值

I have a HTML form with multiple inputs.

I have the below php code to get them inputs and put them in an associated array.

However, when dumping the Associated array the value only shows the first letter...

<?php
$valueArray=array
(
  "servername"=>'',
  "serverlocation"=>'',
  "servertype"=>'',
  "serverdescription"=>''
);

 foreach($valueArray as $key => $value)
{
  if (isset($_POST[$key]))
  {
   $postValue = $_POST[$key];
   $actualValue = $postValue;
   $valueArray[$key][$value] = $actualValue;
 }
}

var_dump($valueArray);


?> 

This is what is dumped -

array(4) { ["servername"]=> string(1) "d" ["serverlocation"]=> string(1) "K" ["servertype"]=> string(1) "P" ["serverdescription"]=> string(1) "t" } post

How do i get it to store the whole string, and not just the first letter?

  • 写回答

2条回答 默认 最新

  • doumaji6215 2018-09-21 18:59
    关注

    If you want to fill the valueArray with the content of the POST request you have to do this:

    $valueArray=array
    (
      "servername"=>'',
      "serverlocation"=>'',
      "servertype"=>'',
      "serverdescription"=>''
    );
    
     foreach($valueArray as $key => $value)
    {
      if (isset($_POST[$key]))
      {
       $postValue = $_POST[$key];
       $valueArray[$key] = $postValue;
     }
    }
    
    var_dump($valueArray);
    

    I think you ar wrong with this line:

    $valueArray[$key][$value] = $actualValue;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?