Illegal string offset Warning PHP
Please try this way.... I have tested this code.... It works....
$memcachedConfig = array("host" => "127.0.0.1","port" => "11211");
print_r($memcachedConfig['host']);
How to fix this `Illegal string offset` error in php?
use isset
function because your 0 index is empty in $row
foreach ($rows as $k => $value) {
if(isset($value['news_id'])){
$id = $value['news_id'];
$title = $value['news_title'];
echo $title;
}
}
you should add check (condition) when you assign data to $rows
Warning: Illegal string offset PHP 7 foreach
You need to check whether ProdIt
is 1-dimensional or 2-dimensional. In the first example, it's a single associative array, not an array of associative arrays.
$prodit = $jsonRes['prod']['ret']['ProdIt'];
if (is_array($prodit)) {
if (isset($prodit['Article'])) { // 1-dimensional, turn into 2-dimensional
$prodit = array($prodit);
}
foreach ($prodit as $obRes) {
...
}
}
How do I fix these illegal string offset warnings?
The usage of the function is_array()
in the beginning of your function can give you the insurance, that, if someone pass you something else than an array, the variable is reinitialised as an empty array.
Unsetting or nulling it before doing that is useless, because, as of PHP 5.3, PHP does have a garbage collector mechanism.
/**
* @params array $array
*/
function my_function( $array ) {
if ( ! is_array ( $array ) ) { $array = [] };
/**
* Or, if you don't like the short array notation:
* if ( ! is_array ( $array ) ) { $array = array(); };
*/
if ( ! isset( $array['where'] ) ) { $array['where'] = 'after'; }
if ( ! isset( $array['echo'] ) ) { $array['echo'] = false; }
if ( ! isset( $array['content'] ) ) { $array['content'] = false; }
$array['shortcode'] = true;
$array['devs'] = true;
return social_warfare( $array );
}
add_shortcode( 'my_shortcode', 'my_function' );
Opencart module error: Warning: Illegal string offset 'model' in opencart/admin/model/catalog/product.php
The issue was resolved after I restructured the array. The sub-array should have a child array with language_id as a key inside of it.
The functional array should be stuctured like this:
$products_data_array[] = array(
'product_description' => array(
'0' => array(
'name' => $name,
'meta_description' => $meta_description,
'meta_title' => $meta_title,
'meta_keyword' => $meta_keyword,
'description' => $description,
'tag' => $tag,
)
),
'mciid' => $mciid,
'model' => $model,
'sku' => '',
'upc' => '',
'ean' => '',
'jan' => '',
'isbn' => '',
'mpn' => '',
'location' => '',
'price' => $price,
'tax_class_id' => '',
'quantity' => '',
'minimum' => '',
'subtract' => '',
'stock_status_id' => '5',
'shipping' => '',
'keyword' => '',
'image' => '',
'date_available' => '',
'length' => '',
'width' => '',
'height' => '',
'length_class_id' => '',
'weight' => $weight,
'weight_class_id' => '',
'status' => '1',
'sort_order' => '',
'manufacturer' => $brand,
'manufacturer_id' => '111',
'category' => $category,
'filter' => '',
'product_store' => array(
'0' => 0
),
'download' => '',
'related' => '',
'product_attribute' => array(
'0' => array(
'name' => '',
'attribute_id' => '',
'product_attribute_description' => array(
'1' => array(
'text' => "first language content"
)
)
)
),
'option' => '',
'points' => '',
'product_reward' => array(
'1' => array(
'points' => ''
)
),
'product_layout' => array(
'0' => array(
'layout_id' => '2'
)
)
);
Note: This array is functional on Version 3.0.3.8 of Opencart.
Related Topics
Pdoexception "Could Not Find Driver"
What Is the Use of the @ Symbol in PHP
How to Encrypt and Decrypt a PHP String
PHP Function to Generate V4 Uuid
Convert Base64 String to an Image File
Move_Uploaded_File Gives "Failed to Open Stream: Permission Denied" Error
How to Solve PHP Error 'Notice: Array to String Conversion In...'
Understanding MVC Views in PHP
Send Email from Localhost Running Xammp in PHP Using Gmail Mail Server
How to Secure Database Passwords in PHP
Parse Xml With Namespace Using Simplexml
Check If PHP Session Has Already Started
Creating Default Object from Empty Value in PHP