0

I want to check my input form with PHP.

And I want to fill an array with the false inputsbox name and the reason.

But I don't know how I get it multidimensional.

e.g.

$false = array();

if (!isset($_POST['name']) OR $_POST['name'] == "") {
    array_push($false, "name");
    //and here I want to to get a multi-dimension array and put the reason of the fales the the arraykey name
    //e.g. Sorry the name is missing!
}

if (strlen($_POST['name']) < 3) {
    array_push($false, "name");
    //and here I want to to get a multi-dimension array and put the reason of the fales the the arraykey name
    //e.g. Sorry the name is to short!
}

And now I want to get (if in the input form name stand nothing after submit) e.g.

false
(
    [0] => name
                (
                    [0] => Sorry the name is missing!
                    [1] => Sorry the name is to short!
                    [2] => etc etc
                )
    [1] => etc
                (
                    [0] => etc etc
                )
)

Could somebody please help me?

4
  • $false = array(); $false[] = $_POST; something like that? Commented Jan 4, 2012 at 13:00
  • No. In my example I write in the array "false" the input "name" and now i want to put the reason to the to the array kay "name". Commented Jan 4, 2012 at 13:11
  • $false = array(); $false['name'][] = $_POST['name']; will work Commented Jan 4, 2012 at 14:40
  • Sorry just realised that someone below me had posted xD Commented Jan 4, 2012 at 14:40

1 Answer 1

1
$false = array();

if (!isset($_POST['name']) OR $_POST['name'] == "") {
    $false['name'][] = 'Sorry the name is missing!';
}

if (strlen($_POST['name']) < 3) {
    $false['name'][] = 'Sorry the name is to short!';
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks it works... but now I cant find with in_array the key name. i want to test: if(in_array("name", $false)) { // do something }
if($false['name']) { //do something }
if( array_key_exists( 'name', $false ) ){ //do something }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.