Jump to content

Using array from previous function


john_doemoor

Recommended Posts

You could do two things, depending on use.  Either return a value, or pass the value to another function.

 

function one() {
    $array = array('one', 'two');

    return $array;
}

$test = one();

// OR

function one() {
    $array = array('one', 'two');

    two($array);
}

function two( $data = array() ) {
    empty( $data ) return FALSE;

    ... some code ...
}

You could also use classes, I think.

<?php
class Beginning{
    function Opening(){
         ['your code']
     }
}
class End extends Beginning{
    function End(){
        ['ending code']
    }
}

 

That would be a horrible use of classes.

 

Again, john_doemoor, show the code you're having issues with.

So my issue is, i need to use:

public function parseLogLines($logLines, $householdId) {
	$logLinesArray = array();
	foreach(preg_split("/\n|\r/", $logLines) as $logLine) {
		if (preg_match("/$householdId/", $logLine) > 0) {
			$logLineArray = preg_split("/,/",$logLine, 2, PREG_SPLIT_NO_EMPTY);

			$index = $logLineArray[0];
			$content = $logLineArray[1];
			$logLinesArray[$index] = $content;
		}		
	}
	return $logLinesArray;
}

at next function, and at next function i parse more loglines with this function, and i need all of the loglines stay in an array.

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.