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条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改