duanpanhuo0618 2014-08-06 13:13
浏览 31
已采纳

显示数组数组的随机值

Below is a array generated by a query builder.

   $random_array =  Array ( [0] => Array ( [text] => A great time was had by all! ) 
            [1] => Array ( [text] => KILL SHOT ) 
            [2] => Array ( [text] => How is it possible) 
            [3] => Array ( [text] => http://www.youtube.com/watch?v=KwGOZpbxU9g ) 
            [4] => Array ( [text] => http://www.youtube.com/watch?v=KwGOZpbxU9g ) 
          )

Currently i am doing like this to print the random value

print_r(array_rand($random_array,1));

This is printing the array key as 3 or 1 etc(random from above array).I want to print the value of the key and not the key.

e.g I want to print the random value like this "http://www.youtube.com/watch?v=KwGOZpbxU9g" or "A great time was had by all!" instead of 3 or 1 which is printing now.

Is it possible to do this.

  • 写回答

2条回答 默认 最新

  • dongyan1808 2014-08-06 13:20
    关注

    You will have one more line of code as shown below:

    $array_key = array_rand($random_array,1); //get the key
    print_r( $random_array[$array_key] );     //use the key to print value
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

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