PHP

Move array to bottom or to top

function moveArrayKeyToTop(&$array, $key) { $temp = array($key => $array[$key]); unset($array[$key]); $array = $temp + $array; } function moveArrayKeyToBottom(&$array, $key) { $value = $array[$key]; unset($array[$key]); $array[$key]

Read More »

Convert MySQL column names to PHP array

function getTableColumnNames($table) { if ($table) { $query = “SHOW COLUMNS FROM ” . $table; $res = $GLOBALS[‘TYPO3_DB’]->sql_query($query); $fields = array(); while ($row = $GLOBALS[‘TYPO3_DB’]->sql_fetch_assoc($res)) {

Read More »

HEX to RGB

function hex2rgb($hex) { if ($hex) { $hex = str_replace(‘#’, ”, $hex); if (strlen($hex) == 3) { $r = hexdec(substr($hex, 0, 1) . substr($hex, 0, 1));

Read More »

Sort array by key (human order)

function natksort(&$array) { $keys = array_keys($array); natcasesort($keys); if (is_array($keys) && count($keys)) { foreach ($keys as $k) { $new_array[$k] = $array[$k]; } } $array = $new_array;

Read More »

Compare string by array

function stristr_array($string, $needleArray) { if (!is_array($needleArray)) { return false; } if (is_array($needleArray) && count($needleArray)) { foreach ($needleArray as $needle) { if (stristr($string, $needle)) { return

Read More »

Most Popular