Page 1 of 1

Array help, looping through array to check for content.

Posted: Wed Oct 04, 2006 9:45 am
by akimm
I am trying to help a user on here, I've made this array, and a function that takes the value of $_POST['name'] and checks to see if it exists within an array. Somewhere along the line I am screwing up. As I said this is for someone else, just trying to help

test1_array.php

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('html_errors', false);
$users_array = array(
'bob',
'lisa'
);
function users_array() {
$value = $_POST['name'];
   if (!is_array($users_array)) {
	echo "this is not an array";
   return false;
   } else {
   while (in_array($value)) {
	   echo "user found";
			break;
	       return true;
       }
echo "you're not in there";
   break;
   return false;
		}
return users_array();
			}
?>
the form

Code: Select all

<form method="POST" action="test1_array.php">
<h1>your name </h1>
<input type="text" name="name">
<input type="submit" value="submit this" name="submit">
</form>

Posted: Wed Oct 04, 2006 9:59 am
by volka
while (in_array($value))
why while?
in_array($value)
What is this supposed to do?
function users_array() {
$value = $_POST['name'];
if (!is_array($users_array)) {
please read http://www.php.net/manual/en/language.v ... .scope.php


why not simply

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('html_errors', false);

$users_array = array('bob','lisa');
echo in_array($_POST['name'], $users_array) ? 'true':'false';
?>
?