Jump to content

Three-Dimensional Array, help!


jamesxg1

Recommended Posts

Hiya peeps!

 

Here are my scripts;

 

test.php

<?php
include 'formValidation.php';
$new = new formValidation(
					array(
							array(
								'formname' => 'firstname',
								'value' => 'james',
								'options' => 'required, alllowercase, onlyletters',
								'name' => 'First Name'
								),
								array(
								'formname' => 'password',
								'value' => 'blahblah',
								'options' => 'required, oneuppercase, alphanumerical',
								'name' => 'Password'
								),
								array(
								'formname' => 'username',
								'value' => 'blahblah',
								'options' => 'required, oneuppercase, alphanumerical',
								'name' => 'Username'
								)
						)
					);
?>

 

formValidation.php

<?php
class formValidation {

	private $inputs;

	function __construct($inputs = array()) {
		foreach($inputs as $input_key => $input_value) {
			foreach($input_value as $key => $value) {
				echo $value . '<br />';
			}
		}
	}

	public function __prep($formname, $options, $value, $name) {

		echo $formname . ' ' . $options . ' ' . $value . ' ' . $name . '<br />';

	}
}
?>

 

This outputs;

 

firstname
james
required, alllowercase, onlyletters
First Name
password
blahblah
required, oneuppercase, alphanumerical
Password
username
blahblah
required, oneuppercase, alphanumerical
Username

 

But what i need to do is for every four values I need them to be sent to the __prep function. EG;

 

$this->__prep('firstname', 'required, alllowercase, onlyletters', 'james', 'First Name');

 

I have no idea how to do this tho, I have tried a for() loop, another foreach loop, array the first four values then foreaching them again. I'm stuck, someone please help!

 

Many thanks,

 

James.

Link to comment
https://forums.phpfreaks.com/topic/216000-three-dimensional-array-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.