当前位置: 首页>>代码示例>>PHP>>正文


PHP Arrays::find方法代码示例

本文整理汇总了PHP中Arrays::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Arrays::find方法的具体用法?PHP Arrays::find怎么用?PHP Arrays::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Arrays的用法示例。


在下文中一共展示了Arrays::find方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: find

	/**
	 * Search a value in a (multidimensional) array - replacement for array_search().
	 *
	 * This function returns the key of the element that contains the specified keyword.
	 * The element can be an array, it will be recursively scanned for the keyword.
	 * The key of the parent element (not the child element) which contains the keyword
	 * will be returned. If there are more than one elements with the specified keyword
	 * the key of the first found element will be returned. If nothing is found boolean
	 * FALSE will be returned.
	 *
	 * Example:
	 * <code>
	 * $mimeTypes = array(
	 *	'image/gif' => array('gif'),
	 *	'image/jpeg' => array('jpe', 'jpeg', 'jpg'),
	 *	'image/png' => array('png', 'x-png'),
	 * );
	 * echo Arrays::find($mimeTypes, 'jpg');
	 * // Output: image/jpeg
	 * </code>
	 *
	 * @param array Array to search in
	 * @param mxied Text to find
	 * @return mixed Key of array or false on failure
	 */
	public static function find(array $array, $keyword) {
		foreach($array as $key => $value) {
			if($keyword === $value || (is_array($value) == true && Arrays::find($array, $value) !== false)) {
				return $key;
			}
		}
		return false;
	}
开发者ID:BackupTheBerlios,项目名称:viscacha-svn,代码行数:33,代码来源:class.Arrays.php

示例2: getMimeType

	/**
	 * Returns the mime type for a specified file.
	 *
	 * You can specify the path to a file or an extension (with our without leading dot).
	 * If you specify a valid file name we try to use the fileinfo extension to 
	 * determine the mime type, if this fails we use the mapping array.
	 * If you specify an invalid file or just an extension we use the mapping array.
	 * This function returns a mime type (in lowercase) for an extension.
	 * NULL will be returned if no mime type is found.
	 * 
	 * Note: Be careful when specifying files like .htaccess or README. 
	 * This could be a valid file or an extension, this function assumes that
	 * every input is a vlid file and, if this fails, we check for the extension mapping.
	 * 
	 * @link http://www.php.net/fileinfo
	 * @param string File extension without dot
	 * @return string Mime type
	 */
	public static function getMimeType($file) {
		$mimeType = false;
		if (class_exists('finfo', false) && file_exists($file)) {
			$finfo = new finfo(FILEINFO_MIME_TYPE);
			if ($finfo) {
				$mimeType = $finfo->file($file);
			}
		}
		if ($mimeType === false) {
			$ext = new File($file);
			$mimeType = Arrays::find(self::$data, $ext->extension());
		}
		return ($mimeType === false) ? null : $mimeType;
	}
开发者ID:BackupTheBerlios,项目名称:viscacha-svn,代码行数:32,代码来源:class.MimeType.php


注:本文中的Arrays::find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。