How pass data between methods PHP. Code examples open

How pass data between methods PHP. Code examples

Tested: PHP 5.6 +
function method1($data){
  // Do something with $data
  method2($data);
}

function method2($data){
  // Do something with $data
}
$data = 'Hello World!';

function method1(){
  global $data;
  // Do something with $data
  method2();
}

function method2(){
  global $data;
  // Do something with $data
}
function method1(){
  $data = 'Hello World!';
  return $data;
}

function method2(){
  $data = method1();
  // Do something with $data
}

In WP:

function method1($data){
  // Do something with $data
  do_action('my_custom_hook', $data);
}

function method2($data){
  // Do something with $data
}
add_action('my_custom_hook', 'method2');
0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation