note 87513 added to function.array-flip

From: Date: Mon, 08 Dec 2008 09:36:37 +0000
Subject: note 87513 added to function.array-flip
Groups: php.notes 
Request: Send a blank email to php-notes+get-147908@lists.php.net to get a copy of this message
<?php /* Fun function to return the longest physical *value* from an array. Culled from a small script designed to capture the longest $_POST variable, usually the textarea, which would then be dumped to a "emergency post dump file". corz at corz dot org */ $array = array("input" => "submit", "textarea" => "Some long spiel of text\r\na textarea, probably", "another-input" => "make me longer", "and" => "another", "etc" => "etc."); echo '<!DOCTYPE HTML SYSTEM><html><head><title>long</title></head><body><pre>Longest value: ', get_longest_value($array),'</pre></body></html>'; function get_longest_value($array) { foreach ($array as $key => $value) { $lengths[$key] = strlen($value); } asort($lengths); $lengths = array_flip($lengths); $longest = str_replace("\r\n", "\n", $array[array_pop($lengths)]); if (get_magic_quotes_gpc()) { return stripslashes($longest); } return $longest; } ?> ---- Server IP: 92.48.74.199 Probable Submitter: 92.8.98.171 ---- Manual Page -- http://www.php.net/manual/en/function.array-flip.php Edit -- https://master.php.net/note/edit/87513 Del: integrated -- https://master.php.net/note/delete/87513/integrated Del: useless -- https://master.php.net/note/delete/87513/useless Del: bad code -- https://master.php.net/note/delete/87513/bad+code Del: spam -- https://master.php.net/note/delete/87513/spam Del: non-english -- https://master.php.net/note/delete/87513/non-english Del: in docs -- https://master.php.net/note/delete/87513/in+docs Del: other reasons-- https://master.php.net/note/delete/87513 Reject -- https://master.php.net/note/reject/87513 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#147908) next »