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 7458503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:27:22+00:00 2026-05-29T13:27:22+00:00

The following method below works perfectly if $output is a string. Although in a

  • 0

The following method below works perfectly if $output is a string. Although in a rare case $output can be passed as an array.

How can I check if $output is an array and to only get the last part of the array.

/**
 * Output writer.
 *
 * @param string $output
 * @param Controller $oController
 * @throws Output_Exception
 */
public static function factory($output,Controller $oController) {       

    $outtype =  ucfirst(strtolower(str_replace(".","_",$output)));
    $classname = __CLASS__ . "_" . $outtype;

    try {

        Zend_Loader::loadClass($classname);
        $oOutputter = new $classname($oController);

        if(! $oOutputter instanceof Output_Abstract )
            throw new Output_Exception("class $classname is not an instance of Output_Abstract");

    } catch (Zend_Exception $e) {               
        throw $e;
    }

    return $oOutputter;
}

Errors:

Warning: strtolower() expects parameter 1 to be string, array given in
C:\wamp\www\cms\webapp\library\Output.php on line 16

Warning: include_once(Output.php) [function.include-once]:
failed to open stream: No such file or directory in
C:\wamp\php\includes\Zend\Loader.php on line 146

var_dump($output)

array(2) { [0]=> string(6) "xml" [1]=> string(6) "smarty" } 
  • 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-29T13:27:23+00:00Added an answer on May 29, 2026 at 1:27 pm

    You should be able to use PHP’s is_array() function. Something like the following should do it.

    <?php
    //...
    $output = is_array($output) ? $output[count($output)-1] : $output;
    //...
    ?>
    

    This snippet will check if $output is an array, and if it is, it’ll set $output to to the last element in the array. Otherwise, it will leave it unchanged.

    You can read more about is_array() at the following link:

    http://www.php.net/manual/en/function.is-array.php

    EDIT: Looks like someone beat me to an answer, but I would recommend against using the end() function here. Doing so could have unexpected results if the code calling your function expects the array to be unmodified.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code works perfectly. My only concern is that I wanna convert below
The method below called UserCanAccessThisPage is based on the following logic: each user and
Given the following situation (UML below), If Y has the method: public void PrintWs();
The following method, when called with something like String val = getCell(SELECT col FROM
I am decoding a file using the following method: string outFileName = zfoFileName.Replace(.zfo, _tmp.zfo);
The following method of course works, but after a certain number of uploads (this
The following segment of code shows JOptionPane.showInputDialog() method. It works fine, Now I want
I use the following line of code within a single method to explicitly check
I have the following LINQ method that works as expected except if there are
The following method does not work because the inner block declares a variable of

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.