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 ...
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.