Skip to content

Instantly share code, notes, and snippets.

@thefrosty
Created October 4, 2012 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thefrosty/3835942 to your computer and use it in GitHub Desktop.
Save thefrosty/3835942 to your computer and use it in GitHub Desktop.
Returns Undefined index
$defaults = array(
'company' => 'client_company',
'address_1' => 'client_address_1',
'address_2' => 'client_address_2',
'city' => 'client_city',
'state' => 'client_state',
'postcode' => 'client_postcode',
'country' => 'client_country'
);
/**
* Parse incomming $args into an array and merge it with $defaults
*/
$args = wp_parse_args( $args, $defaults );
/**
* OPTIONAL: Declare each item in $args as its own variable i.e. $type, $before.
*/
extract( $args, EXTR_SKIP );
//print_r( $args ); return;
$user_meta = array();
foreach ( $args as $label => $value ) {
$user_meta[$label] .= get_user_meta( $user_id, $value, true );
}
return $user_meta;
@thefrosty
Copy link
Author

With the $user_meta array using the $label it gives a undefined index of all the default args labels. With out the $label in the $user_meta array it's fine but outputs the count.

$user_meta[$label]:
Array
(
[company] =>
[address_1] =>
[address_2] =>
[city] =>
[state] =>
[postcode] =>
[country] =>
)

$user_meta[]:
Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment