數組判斷輸出

來源:互聯網
上載者:User
數組A 與數組B,要輸出A的值,A中的值比B多,A中有幾個列是必須要輸出的,那麼對比A與B,如果有相同的值才會輸出,求指教。。。。


回複討論(解決方案)

取交集? 舉例說明一下。

foreach($a as $aa) {
if(in_array($aa, $b)) {
echo $aa;
//這樣嗎?
}
}

很簡單的

foreach($A as $key =>$val){  if(in_array($val,$B)){//在數組B中才顯示    echo $val;  }}

取交集? 舉例說明一下。 Jordan哥,我一直線上等著你呢,我給你留言說明了我的問題了,你能再幫我看看不?

很簡單的

foreach($A as $key =>$val){  if(in_array($val,$B)){//在數組B中才顯示    echo $val;  }}


但是數組A的第一,第二列不需經過判斷,其他列需要經過判斷,另外要求數組A需要用switch來組合
到數組C中。。。而switch中不能進行判斷

你應該給出樣本資料
不存在一成不變的演算法

沒發現徐版主的回複

取交集? 舉例說明一下。

//搜尋單個商品的所有資訊$item_info = $goods->get_item($item_id,$shop_id);$list_array = array();//得到目前使用者的許可權$uid = $_SESSION['uid'];$access = $_SESSION['access'];$rows = $users->get_access_row($access);if(in_array($key,$rows){}$cid = $item_info['item_cid'];foreach($item_info as $key=>$item){switch($key){//不需判斷case 'item_id':$list_array[] = array("key"=>$key,"text"=>'商品id',"value"=>$item);break;case 'shop_id':$list_array[] = array("key"=>$key,"text"=>'店鋪id',"value"=>$item);break;//以下需要判斷case 'item_code':$list_array[] = array("key"=>$key,"text"=>'商家編碼',"value"=>$item);break;case 'onsale':$list_array[] = array("key"=>$key,"text"=>'是否上架',"value"=>$item);break;case 'item_cid':$item_cid_name = $goods->get_item_cid($item);$list_array[] = array("key"=>$key,"text"=>'商品分類',"value"=>$item_cid_name);break;case 'item_desc':$list_array[] = array("key"=>$key,"text"=>'商品描述',"value"=>$item);break;case 'item_title':$list_array[] = array("key"=>$key,"text"=>'商品標題',"value"=>$item);break;case 'item_stuff_status':$list_array[] = array("key"=>$key,"text"=>'商品新舊程度',"value"=>$item);break;}}
現在就是不知道對比語句要怎麼寫

你應該給出樣本資料
不存在一成不變的演算法

//搜尋單個商品的所有資訊$item_info = $goods->get_item($item_id,$shop_id);$list_array = array();//得到目前使用者的許可權$uid = $_SESSION['uid'];$access = $_SESSION['access'];$rows = $users->get_access_row($access);if(in_array($key,$rows){}$cid = $item_info['item_cid'];foreach($item_info as $key=>$item){switch($key){//不需判斷case 'item_id':$list_array[] = array("key"=>$key,"text"=>'商品id',"value"=>$item);break;case 'shop_id':$list_array[] = array("key"=>$key,"text"=>'店鋪id',"value"=>$item);break;//以下需要判斷case 'item_code':$list_array[] = array("key"=>$key,"text"=>'商家編碼',"value"=>$item);break;case 'onsale':$list_array[] = array("key"=>$key,"text"=>'是否上架',"value"=>$item);break;case 'item_cid':$item_cid_name = $goods->get_item_cid($item);$list_array[] = array("key"=>$key,"text"=>'商品分類',"value"=>$item_cid_name);break;case 'item_desc':$list_array[] = array("key"=>$key,"text"=>'商品描述',"value"=>$item);break;case 'item_title':$list_array[] = array("key"=>$key,"text"=>'商品標題',"value"=>$item);break;case 'item_stuff_status':$list_array[] = array("key"=>$key,"text"=>'商品新舊程度',"value"=>$item);break;}}

比對

case 'item_code' && in_array($key, $row):

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.