奶头挺立呻吟高潮av全片,成人试看120秒体验区,性欧美极品v,A片高潮抽搐揉捏奶头视频

php語言

php5.5新數(shù)組函數(shù)array-column使用實(shí)例

時(shí)間:2025-03-04 16:02:09 php語言 我要投稿
  • 相關(guān)推薦

php5.5新數(shù)組函數(shù)array-column使用實(shí)例

  導(dǎo)語:PHP5.5發(fā)布了,其中增加了一個(gè)新的數(shù)組函數(shù)array_column。下面的是百分網(wǎng)小編為大家搜集的php5.5新數(shù)組函數(shù)array_column使用實(shí)例,希望對(duì)你有所幫助。

  復(fù)制代碼 代碼如下:

  if(!function_exists('array_column')){

  function array_column($input, $columnKey, $indexKey=null){

  $columnKeyIsNumber      = (is_numeric($columnKey)) ? true : false;

  $indexKeyIsNull         = (is_null($indexKey)) ? true : false;

  $indexKeyIsNumber       = (is_numeric($indexKey)) ? true : false;

  $result                 = array();

  foreach((array)$input as $key=>$row){

  if($columnKeyIsNumber){

  $tmp            = array_slice($row, $columnKey, 1);

  $tmp            = (is_array($tmp) && !empty($tmp)) ? current($tmp) : null;

  }else{

  $tmp            = isset($row[$columnKey]) ? $row[$columnKey] : null;

  }

  if(!$indexKeyIsNull){

  if($indexKeyIsNumber){

  $key        = array_slice($row, $indexKey, 1);

  $key        = (is_array($key) && !empty($key)) ? current($key) : null;

  $key        = is_null($key) ? 0 : $key;

  }else{

  $key        = isset($row[$indexKey]) ? $row[$indexKey] : 0;

  }

  }

  $result[$key]       = $tmp;

  }

  return $result;

  }

  }

  // 使用例子

  $records = array(

  array(

  'id' => 2135,

  'first_name' => 'John',

  'last_name' => 'Doe'

  ),

  array(

  'id' => 3245,

  'first_name' => 'Sally',

  'last_name' => 'Smith'

  ),

  array(

  'id' => 5342,

  'first_name' => 'Jane',

  'last_name' => 'Jones'

  ),

  array(

  'id' => 5623,

  'first_name' => 'Peter',

  'last_name' => 'Doe'

  )

  );

  $firstNames = array_column($records, 'first_name');

  print_r($firstNames);

  /*

  Array

  (

  [0] => John

  [1] => Sally

  [2] => Jane

  [3] => Peter

  )

  */

  $records = array(

  array(1, 'John', 'Doe'),

  array(2, 'Sally', 'Smith'),

  array(3, 'Jane', 'Jones')

  );

  $lastNames = array_column($records, 2);

  print_r($lastNames);

  /*

  Array

  (

  [0] => Doe

  [1] => Smith

  [2] => Jones

  )

  */

  $mismatchedColumns = array(

  array(

  'a' => 'foo',

  'b' => 'bar',

  'e' => 'baz'

  ),

  array(

  'a' => 'qux',

  'c' => 'quux',

  'd' => 'corge'

  ),

  array(

  'a' => 'grault',

  'b' => 'garply',

  'e' => 'waldo'

  ),

  );

  $foo = array_column($mismatchedColumns, 'a', 'b');

  print_r($foo);

  /*

  Array

  (

  [bar] => foo

  [0] => qux

  [garply] => grault

  )

  */

  array_column 用于獲取二維數(shù)組中的元素(PHP 5 >= 5.5.0)

  復(fù)制代碼 代碼如下:

  <?php

  // Array representing a possible record set returned from a database

  $records = array(

  array(

  'id' => 2135,

  'first_name' => 'John',

  'last_name' => 'Doe',

  ),

  array(

  'id' => 3245,

  'first_name' => 'Sally',

  'last_name' => 'Smith',

  ),

  array(

  'id' => 5342,

  'first_name' => 'Jane',

  'last_name' => 'Jones',

  ),

  array(

  'id' => 5623,

  'first_name' => 'Peter',

  'last_name' => 'Doe',

  )

  );

  $first_names = array_column($records, 'first_name');

  print_r($first_names);

  ?>

  Array

  (

  [0] => John

  [1] => Sally

  [2] => Jane

  [3] => Peter

  )<?php

  // Using the $records array from Example #1

  $last_names = array_column($records, 'last_name', 'id');

  print_r($last_names);

  ?>

  Array

  (

  [2135] => Doe

  [3245] => Smith

  [5342] => Jones

  [5623] => Doe

  )

【php5.5新數(shù)組函數(shù)array-column使用實(shí)例】相關(guān)文章:

C語言的數(shù)組與函數(shù)02-28

PHP數(shù)組函數(shù)知識(shí)05-09

C語言數(shù)組實(shí)例解析02-21

Java數(shù)組的使用07-14

關(guān)于PHP數(shù)組函數(shù)知識(shí)01-15

簡單PHP數(shù)組函數(shù)介紹05-10

對(duì)C語言數(shù)組的總結(jié)以及實(shí)例講解03-13

PHP自帶的幾個(gè)實(shí)用的數(shù)組函數(shù)08-10

主站蜘蛛池模板: 明光市| 方山县| 施甸县| 商河县| 合作市| 南汇区| 株洲市| 和林格尔县| 方正县| 高州市| 罗平县| 山丹县| 巍山| 潞城市| 平湖市| 白银市| 甘南县| 扎赉特旗| 兴化市| 台州市| 西丰县| 巴彦县| 花莲市| 两当县| 当雄县| 蓬安县| 廉江市| 莱芜市| 宁都县| 射阳县| 闸北区| 宁武县| 温泉县| 镇康县| 商丘市| 长乐市| 安泽县| 古蔺县| 长葛市| 根河市| 黄龙县|