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 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)