doushui20090526 2018-04-17 06:37
浏览 118
已采纳

提取第一个数组的子字符串以从PHP中获取第二个数组的匹配值

Given as an example:

$store = {A, B, C, D, E}

$price = {2, 10, 1, 500, 20}

Store[0]'s value is 2, [1] is 10, and so on. I'd like to know how to do that. I tried using min() but to no avail (unless I missed something out). Here's what I've done so far:

$x;

for ($x = $price.Count - 1; $x >= 0; $x--)

{

//this is the part where I can't figure it out
//compare prices here
//get the lowest price
//x = theSubstringOfTheLowestPrice

}

echo $store[x];
  • 写回答

4条回答 默认 最新

  • dscuu86620 2018-04-17 06:43
    关注
    1. Your PHP code is not valid: $price = {A} means you must have constant A and php arrays are enclosed with array() or [].

    2. Use array_combine() to create key-value pairs (demo):

    $store = ['A', 'B', 'C', 'D', 'E'];
    
    $price = [2, 10, 1, 500, 20];
    
    $range = array_combine($store, $price);
    
    var_dump($range['D']); // 500
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100