Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7615103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:34:20+00:00 2026-05-31T02:34:20+00:00

I have a small function below that accepts associative arrays and I’m struggling to

  • 0

I have a small function below that accepts associative arrays and I’m struggling to find a way to modify it to accept simpler arrays. It would be easy to create a separate function and remove a foreach loop, but I’m trying to see if there is a more efficient way to achieve this. Any insights would be greatly appreciated.

Function:

public function set_content($file, $data, $section_name)
{
  $jobs = new Template_Engine();
  $jobs->set_file($file);
  $jobs_output = '';

  static $section_title = 0;
  foreach($data as $job)
  {
      //print_r($job);
      foreach($job as $key=>$value)
      {
          $jobs->set($key,$value);
      }

      if ($section_title === 0) 
      {
          $jobs->set("section_title",$section_name);
      }
      else 
      {
          $jobs->clear_set("section_title");    
      }

      ++$section_title;
      $jobs_output .=  $jobs->output();
  }

  $section_title = 0;
  return $jobs_output;
}

Array Sample 1:

Array ( [0] => Array ( [custom_id] => 78 [name] => Title Goes [description] => Test [resume_id] => 96 [order_id] => 0 [section_id] => 224 [profile_id] => 38 [user_id] => 1 [vanity_name] => Sample of Template 3 [template_id] => 3 [date_add] => 0000-00-00 00:00:00 [date_mod] => 2012-03-04 11:00:05 ) [1] => Array ( [custom_id] => 76 [name] => A Custom Item [description] => A descrition for a custom item goes here. [resume_id] => 96 [order_id] => 1 [section_id] => 224 [profile_id] => 38 [user_id] => 1 [vanity_name] => Sample of Template 3 [template_id] => 3 [date_add] => 0000-00-00 00:00:00 [date_mod] => 2012-03-04 11:00:05 ) )

Array Sample 2:

Array ( [list_item] => EnglishSpanishFrenchCatalanJapanese )
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:34:22+00:00Added an answer on May 31, 2026 at 2:34 am

    Add an IF before the foreach($job as $key=>$value) to check if the first item is an array or not:

    ...
    if (is_array($job)) {
      foreach($job as $key=>$value)
      {
        $jobs->set($key,$value);
      }
    } else {
      // treat here the value of the more simpler array; 
      // in this case, $job would contain EnglishSpanishFrenchCatalanJapanese
    }
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JS function that does Ajax for me and another like
I have a small C# function that takes any generic SQLDataReader and converts it
I have this small function that is causing me headaches on RHEL6, and I
I have several newbie questions concerning eigen. Below is a small function to illustrate
I have a small function that runs on load and window resize.. but the
I have a small sample function: #define VALUE 0 int test(unsigned char x) {
I have functions that contribute to small parts of a figure generation. I'm trying
I have a small 3D vector class in C# 3.0 based on struct that
I have written a small function, which uses ElementTree and xpath to extract the
I have a small codeigniter controller. Below is the code class Example extends CI_Controller

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.