How to pass multiple variables as parameters in PHP?
-
Hi there,
I have a function which retrieves all the terms of all the taxonomies associated to a post. But I have a basic issue with creating PHP function.
I expect to call my function (see the code below) by passing as parameters all the variable I have defined IN the function.
function get_tax_terms_for_the_product() { // Get post by post ID. if ( ! $post = get_post() ) { return ''; } // Get post type by post. $post_type = $post->post_type; // Get the singular_name of the cpt $post_type_obj = get_post_type_object( $post_type ); // Get post type taxonomies. $taxonomies = get_object_taxonomies( $post_type, 'objects' ); foreach ( $taxonomies as $taxonomy_slug => $taxonomy ){ // Get the terms related to post. $terms = get_the_terms( $post->ID, $taxonomy_slug ); if ( ! empty( $terms ) ) { // We switch the HTML output in order to give them custom CSS classes switch ($taxonomy_slug) { case "tax-plates-formes": $info_plates_formes[] .= '<li class="info-plateformes">'.$term->name.'</li>'; break; case "tax-categories": $info_categories[] .= '<li class="info-categories">'.$term->name.'</li>'; break; } } } }
I expect to call my function like this to echo the VALUE of the $variable :
// Echo $info_categorie value (STRING) function get_tax_terms_for_the_product($info_categories) or // Echo $info_plates_formes value (STRING) function get_tax_terms_for_the_product($info_plates_formes)
Can someone help me for this? I’m blocked for 2 days for a simple basic PHP ??
Thank you.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to pass multiple variables as parameters in PHP?’ is closed to new replies.