本文整理汇总了PHP中ArrayHelper::format方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::format方法的具体用法?PHP ArrayHelper::format怎么用?PHP ArrayHelper::format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayHelper
的用法示例。
在下文中一共展示了ArrayHelper::format方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFormatWithSameKeysOnDifferentLevels
public function testFormatWithSameKeysOnDifferentLevels()
{
$source = array(0 => array('id' => '13', 'title' => '', 'created_ts' => '2013-10-09 14:50:19', 'initiator_id' => '1', 'participants' => array(0 => array('id' => '25', 'conversation_id' => '13', 'user_id' => '1', 'last_view_ts' => '0000-00-00 00:00:00', 'user' => array('user_id' => '1', 'first_name' => 'Vasiliy', 'last_name' => 'Pedak', 'photo' => '1_0_73787400_1377002601.jpg', 'photo_thmbnl_64' => '1_0_73787400_1377002601_64x64.jpg', 'birth_place' => NULL, 'birth_day' => NULL, 'gender' => NULL, 'mobile_phone' => NULL, 'email' => NULL, 'displayName' => 'Vasiliy Pedak', 'photoThmbnl64' => 'http://aes.dev/uploads/photos/1_0_73787400_1377002601_64x64.jpg', 'pageUrl' => 'http://aes.dev/index-test.php/userPage/1')), 1 => array('id' => '26', 'conversation_id' => '13', 'user_id' => '7', 'last_view_ts' => '0000-00-00 00:00:00', 'user' => array('user_id' => '7', 'first_name' => 'Steve', 'last_name' => 'Jobs', 'photo' => NULL, 'photo_thmbnl_64' => NULL, 'birth_place' => NULL, 'birth_day' => NULL, 'gender' => NULL, 'mobile_phone' => NULL, 'email' => NULL, 'displayName' => 'Steve Jobs', 'photoThmbnl64' => '', 'pageUrl' => 'http://aes.dev/index-test.php/userPage/7'))), 'messages' => array(array('id' => 1, 'created_ts' => '2013-10-09 15:10:02', 'text' => 'foo'), array('id' => 2, 'created_ts' => '2013-10-09 15:12:02', 'text' => 'bar'))));
$tsFormatter = function ($value) {
if (strstr($value, '0000-00-00')) {
return 0;
}
return (int) strtotime($value) * 1000;
};
$formatters = array('created_ts' => $tsFormatter, 'messages.created_ts' => $tsFormatter, 'participants.last_view_ts' => $tsFormatter);
$result = ArrayHelper::format($source, $formatters);
$this->assertEquals((int) strtotime($source[0]['created_ts']) * 1000, $result[0]['created_ts']);
$this->assertEquals(0, $result[0]['participants'][0]['last_view_ts']);
$this->assertEquals(0, $result[0]['participants'][1]['last_view_ts']);
$this->assertEquals((int) strtotime($source[0]['messages'][0]['created_ts']) * 1000, $result[0]['messages'][0]['created_ts']);
$this->assertEquals((int) strtotime($source[0]['messages'][1]['created_ts']) * 1000, $result[0]['messages'][1]['created_ts']);
}
示例2: formatInput
protected function formatInput($array)
{
return ArrayHelper::format($array, $this->inputFormatters);
}