dongxia8656 2015-08-11 09:08
浏览 70

preg_match_all无法在数组中工作

I want to display result after searching an array but only title coming as result, but I want to display more values.

1) If I using following code then entire data coming in long string like

Array
(
[] => SONY CDX-G1150U - CD, USB, FM/AM Tuner with MP3/WMA Playback (Single DIN)59902 Pre-Out (Rear + Sub Switchable) Digital Clarity Tuner Subwoofer Easy Connection EQ3 stage 2 / Bollywood EQ mode / Illumination - Red 55W x 4 Output Power (Dynamic Reality Amp 2) Steering Remote Input Ready Mega Bass 2 Year Sony India Warranty http://www.snapdeal.com/product/sony-cdxg1150u-cd-usb-fmam/914627741http://n1.sdlcdn.com/imgs/a/o/m/SONY-CDX-G1150U-CD-USB-SDL133242160-1-51ec4.jpg311Car Audio & Video310Automotive4017in stock
)

    $r = $array3['title'];
    $r .= $array3['mrp'];
    $r .= $array3['description'];
    $r .= $array3['link'];
    $r .= $array3['image_link'];
    $r .= $array3['sub_category_id'];
    $r .= $array3['sub_category_name'];
    $r .= $array3['category_id'];
    $r .= $array3['category_name'];
    $r .= $array3['offer_price'];
    $r .= $array3['availability'];

$matches = array();

$pattern = "/\bSony\b/";
if(preg_match($pattern,$r) || preg_match($pattern,$ss) ){
        $matches[$key]=$r;
    echo "<pre>";print_r($matches); 

2) If I using following code (with or condition) then also same result displaying.

$r = $array3['title'];
$ss = $array3['mrp'];

$matches = array();

$pattern = "/\bSony\b/";
if(preg_match($pattern,$r) || preg_match($pattern,$ss) ){
        $matches[$key]=$r;
    echo "<pre>";print_r($matches); 
  • 写回答

1条回答 默认 最新

  • dou47732 2015-08-11 09:22
    关注

    If I get you right, try to use something like

    $matches = array();
    foreach($array3 as $key => $value) {
        if(preg_match($pattern, $value)) {
            $matches[] = $array3 
        }
    }
    print_r($matches)
    

    Or by more clear in your question

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大